static void Rotate(float deltaSeconds, LocalToWorld destinationSurfaceLocalToWorld, LocalToWorld surfaceLocalToWorld, NavSteering steering, NavAgent agent, Translation translation, ref Rotation rotation) { var lookAt = (translation.Value + steering.CurrentHeading) .ToWorld(destinationSurfaceLocalToWorld) .ToLocal(surfaceLocalToWorld); lookAt.y = translation.Value.y; var lookRotation = quaternion.LookRotationSafe(lookAt - translation.Value, math.up()); if (math.length(agent.SurfacePointNormal) > 0.01f) { lookRotation = math.mul(lookRotation, math.up().FromToRotation(agent.SurfacePointNormal)); } rotation.Value = math.slerp(rotation.Value, lookRotation, deltaSeconds / agent.RotationSpeed); }
static void Translate(float deltaSeconds, NavSteering steering, NavAgent agent, ref Translation translation) => translation.Value += steering.CurrentHeading * agent.TranslationSpeed * deltaSeconds;