literally half of the game

This commit is contained in:
Sylvia 2026-08-27 04:07:01 -07:00
parent 1590b5faa6
commit b842289076
77 changed files with 11904 additions and 72 deletions

View file

@ -2,4 +2,59 @@ using UnityEngine;
public class Enemy : CombatEntity
{
[Header("Targetting")]
public CombatEntity closestTarget; //actually get the detected target first
public bool detectedPlayer = false;
[Header("Direction")]
public Transform[] possibleDirections;
public float forwardPercent;
public float strafePercent;
public float directionVariance; //how much strafe/forward vary
protected float xSign = -1f;
protected float ySign = 1f;
private void Start()
{
if (Random.Range(0f, 2f) > 1f)
{
xSign = -xSign;
ySign = -ySign;
}
float newVariance = Random.Range(-directionVariance, directionVariance);
forwardPercent += newVariance;
strafePercent -= newVariance;
}
protected override void Movement()
{
if (stalled || !closestTarget || !detectedPlayer || closestTarget.isSafe)
{
moveDirection = Vector3.zero;
}
else
{
Vector2 directionToTarget = (closestTarget.transform.position - 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;
}
}
moveDirection = directionToMove;
//FlipSprite(directionToMove);
// ^ add when you actually draw sprites
}
}
}