public void UpdateSteering() { steeringVector = transform.forward; if (isSeeking && targetTransform != null) { steeringVector = SteeringBehaviors.Seek(cachedTransform.position, velocity, maxSpeed, targetTransform.position); } if (isFleeing && targetTransform != null) { steeringVector = SteeringBehaviors.Flee(cachedTransform.position, velocity, maxSpeed, targetTransform.position); } if (isPursuing && movingTarget != null) { steeringVector = SteeringBehaviors.Pursuit(cachedTransform.position, velocity, maxSpeed, movingTarget.transform.position, movingTarget.velocity); } if (isEvading && movingTarget != null) { steeringVector = SteeringBehaviors.Evasion(cachedTransform.position, velocity, maxSpeed, movingTarget.transform.position, movingTarget.velocity); } if (isArriving && targetTransform != null) { steeringVector = SteeringBehaviors.Arrival(cachedTransform.position, velocity, maxSpeed, targetTransform.position, arrivalSlowingDistance); } if (IsWandering) { steeringVector = Wander(0.5f, 0.1f, false); } if (isLeaderFollowing) { Vector3 leaderFollowPoint = leader.transform.position + leader.transform.forward * -2f; steeringVector = SteeringBehaviors.Arrival(cachedTransform.position, velocity, maxSpeed, leaderFollowPoint, arrivalSlowingDistance); } if (isPathFollowing) { Vector3 possibleSteeringVector = PathFollowing(simplePath); if (possibleSteeringVector != Vector3.zero) { steeringVector = possibleSteeringVector; } } if (isSeperating) { Vector3 repulsionLocation = cachedTransform.position + Seperation(); if (repulsionLocation != cachedTransform.position) { Vector3 desiredVelocity = (repulsionLocation - cachedTransform.position).normalized * maxSpeed; steeringVector = desiredVelocity - velocity; } } if (isAvoidingCollision) { Vector3 collisionSteeringVector = CollisionAvoidance(); if (collisionSteeringVector != velocity) { if (collisionSteeringVector == transform.forward * maxSpeed && steeringVector != transform.forward) { // The previously applied steering vector should not be modified. } else { steeringVector = collisionSteeringVector; } } } if (velocity != Vector3.zero) //Check is to prevent the log message "Look rotation viewing vector is zero" { transform.rotation = Quaternion.LookRotation(velocity); } UpdateMovement(); }