public KinematicSteeringOutput GetSteering() { KinematicSteeringOutput output = new KinematicSteeringOutput(); // Get the direction to the target. Vector3 direction = Character.Target.transform.position - transform.position; direction.y = 0; float targetRotation = Quaternion.LookRotation(direction, Vector3.up).eulerAngles.y; output.Rotation = AngleMapper.MapDegreesMidpointZero(targetRotation); // Check if we’re outside radius. if (direction.magnitude > SatisfactionRadius) { output.Velocity = direction.normalized * Character.MaxSpeed; return(output); // If so, we're done } else if (direction.magnitude > InnerStoppingRadius) { // Otherwise, we use t2t. float adjustedSpeed = Mathf.Min(Character.MaxSpeed, direction.magnitude / TimeToTarget); output.Velocity = direction.normalized * adjustedSpeed; } else { output.Velocity = Vector3.zero; // Stop } return(output); }
public KinematicSteeringOutput GetSteering() { KinematicSteeringOutput output = new KinematicSteeringOutput(); // Get the direction to the target. Vector3 direction = Character.Target.transform.position - transform.position; direction.y = 0; // The velocity is along this direction, at full speed. output.Velocity = Character.MaxSpeed * direction.normalized; //// Face in the direction we want to move. (The TB just straight up changes our direction here) //transform.rotation = Quaternion.LookRotation(direction, Vector3.up); //output.Rotation = 0; float targetRotation = Quaternion.LookRotation(direction, Vector3.up).eulerAngles.y; output.Rotation = AngleMapper.MapDegreesMidpointZero(targetRotation); return(output); }