public override Vector2 SteerForce() { if (path.Size == 0) { _bUsingArrive = false; return(Vector2.zero); } else if (path.Size == 1) { _bUsingArrive = true; arriveSensor.target = path.FirstWaypoint; Arrive2D.SteerForce(Agent, arriveSensor); } if (!path.Finished()) { _bUsingArrive = false; return(Seek2D.SteerForce(path.CurrentWaypoint(), Agent)); } else { _bUsingArrive = true; arriveSensor.target = path.CurrentWaypoint(); return(Arrive2D.SteerForce(Agent, arriveSensor)); } }
public static Vector2 SteerForce(AutonomousAgent2D agent, Collider2D[] colliders, int totalCount, float detectionRadius) { Vector2 positionsSum = Vector2.zero; Vector2 steering = Vector2.zero; Vector2 agentPosition = agent.transform.position; int count = 0; float radiusSq = detectionRadius * detectionRadius; for (int i = 0; i < totalCount; ++i) { var other = colliders[i].GetComponent <AutonomousAgent2D>(); if (other == agent) { continue; } if (agentPosition.WithinDistanceSq(other.transform.position, radiusSq)) { count += 1; positionsSum += (Vector2)other.transform.position; } } if (count > 0) { // The center "mass". Vector2 averagePosition = positionsSum / count; return(Seek2D.SteerForce(averagePosition, agent)); } return(Vector2.zero); }
public override Vector2 SteerForce() { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePosition += Random.insideUnitCircle.normalized * randomDisplacement; return(Seek2D.SteerForce(mousePosition, Agent)); }
public override Vector2 SteerForce() { if (target != null) { return(Seek2D.SteerForce(target.position, Agent)); } return(Vector2.zero); }
public override Vector2 SteerForce() { Vector2 toTarget = targetRigid.position - (Vector2)Agent.transform.position; Vector2 targetVelocityDir = targetRigid.velocity.normalized; float relativeForward = Vector2.Dot(Agent.ForwardDirection, targetVelocityDir); // If the target is head on, then just seek towards it. if (Vector2.Dot(toTarget, Agent.ForwardDirection) > 0 && relativeForward < -0.95f) { _futureSeekCache = targetRigid.position; return(Seek2D.SteerForce(targetRigid.position, Agent)); } float lookAheadTime = toTarget.magnitude / (Agent.maxSpeed + targetRigid.velocity.magnitude); Vector2 future = targetRigid.position + targetRigid.velocity * lookAheadTime; _futureSeekCache = future; return(Seek2D.SteerForce(future, Agent)); }
public override Vector2 SteerForce() { return(Seek2D.SteerForce(_wanderTarget, Agent)); }