this idiot forgot to commit an entire month's worth of code
This commit is contained in:
parent
c67146ea1a
commit
a3321d361c
51 changed files with 3644 additions and 84 deletions
58
Assets/Scripts/Entities/Enemy/RusherEnemy.cs
Normal file
58
Assets/Scripts/Entities/Enemy/RusherEnemy.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
using Core.Extensions;
|
||||
using UnityEngine;
|
||||
|
||||
public class RusherEnemy : Enemy
|
||||
{
|
||||
private bool isRushing;
|
||||
public Vector2 lastTargetLocation;
|
||||
public Vector2 lastTargetDirection;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
if (speedMultiplier <= 1.10f && closestTarget)
|
||||
{
|
||||
lastTargetLocation = closestTarget.transform.position;
|
||||
lastTargetDirection = (lastTargetLocation - (Vector2)transform.position).normalized;
|
||||
}
|
||||
|
||||
}
|
||||
protected override void FixedUpdate() //this is really bad.
|
||||
{
|
||||
if (!detectedPlayer && Vector3.Distance(transform.position, lastTargetLocation) < engagementRange)
|
||||
{
|
||||
detectedPlayer = true;
|
||||
}
|
||||
if (stalled || !closestTarget || !detectedPlayer)
|
||||
{
|
||||
rb.VelocityTowards(Vector2.zero.ScaleToMagnitude(speed), acceleration);
|
||||
}
|
||||
else if (speed > 1.10f && closestTarget)
|
||||
{
|
||||
rb.VelocityTowards(lastTargetDirection.ScaleToMagnitude(speed * speedMultiplier), acceleration);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 directionToTarget = (lastTargetLocation - (Vector2)transform.position).normalized;
|
||||
Vector2 directionToMove = directionToTarget;
|
||||
float currentHighestScore = float.NegativeInfinity;
|
||||
Vector2 strafeDirection = new Vector3(directionToTarget.y * ySign, directionToTarget.x * xSign);
|
||||
foreach (Transform direction in possibleDirections)
|
||||
{
|
||||
Vector3 directionToPoint = (direction.position - transform.position).normalized;
|
||||
float forwardScore = Vector3.Dot(directionToPoint, directionToTarget);
|
||||
float strafeScore = Vector3.Dot(directionToPoint, strafeDirection);
|
||||
float finalScore = (forwardScore * forwardPercent) + (strafeScore * strafePercent);
|
||||
//Debug.Log($"Forward: {forwardScore} Strafe: {strafeScore} Final: {finalScore}");
|
||||
if (finalScore > currentHighestScore)
|
||||
{
|
||||
//Debug.Log($"{finalScore} is higher than current score: {currentHighestScore}");
|
||||
currentHighestScore = finalScore;
|
||||
directionToMove = directionToPoint;
|
||||
}
|
||||
}
|
||||
rb.VelocityTowards(directionToMove.ScaleToMagnitude(speed * speedMultiplier), acceleration);
|
||||
FlipSprite(directionToMove);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue