private SteeringOut Seek(Vector2 targetPos) { Vector2 toTarget = targetPos - _owner.Position; float targetAngle = Utils.Vector2Angle(toTarget); float limitSpeed = DeltaAngle2LimitSpeed(Utils.AbsDeltaAngle (_owner.DegreeHeading(), targetAngle)); return(new SteeringOut(limitSpeed, targetAngle)); }
private SteeringOut Pursuit(MovingAgent targetAgent) { Vector2 toAgent = targetAgent.Position - _owner.Position; float deltaHeadingAngle = Utils.AbsDeltaAngle(_owner.DegreeHeading(), targetAgent.DegreeHeading()); float deltaAngle2Agent = Utils.AbsDeltaAngle(_owner.DegreeHeading(), Utils.Vector2Angle(toAgent)); // If owner and the target agent head to each other // -> Seek straight to target agent if (deltaAngle2Agent < 10 && deltaHeadingAngle < 10) { return(Seek(targetAgent.Position)); } //Else Seek toward the predicted future position float lookAheadTime = toAgent.magnitude / (_owner.Velocity + targetAgent.Velocity); return(Seek(targetAgent.FuturePosition(lookAheadTime))); }