Agent.Arrive C# (CSharp) Method

Arrive() private method

Steering behavior that steers towards a target and attempts to slow down before it reaches the target. Depending on the deceleration radius, max speed, and max force, it may not be able to come to a complete stop.
private Arrive ( ) : Vector3
return Vector3
    private Vector3 Arrive()
    {
        // Scale the speed porporitionally to the distance from the target when within the deceleration radius
        Vector3 targetOffset = this.seekTarget.position - this.transform.position;
        float distance = targetOffset.magnitude;
        float scaledSpeed = (distance / this.decelerationRadius) * this.maxSpeed;
        float desiredSpeed = Mathf.Min (scaledSpeed, this.maxSpeed);

        // Compute the steering force
        Vector3 desiredVelocity = targetOffset.normalized * desiredSpeed;
        return desiredVelocity - this.rb.velocity;
    }