

Use Transform, Rigidbody, Rigidbody2D or nothing at all (if updatePosition = false).
Unity forward vector 2d update#
currentPosition = tr.position // MUST NOT UPDATE FROM TRANSFORM! WILL BREAK DETERMINISM! TODO: Add this into the clampedPosition calculation below to make RVO better respond to physics.

Grab the position after the movement to be able to take physics into account. The Transform may not be at #position if it was outside the navmesh and had to be moved to the closest valid position.Ĭontroller.Move((nextPosition - currentPosition) + accumulatedMovementDelta) If (controller != null & controller.enabled & updatePosition) Vector3 currentPosition = simulatedPosition Use a local variable, it is significantly faster. Velocity2D -= Vector2.ClampMagnitude(velocity2D, acceleration * deltaTime) įinalMovement(simulatedPosition, deltaTime, float.PositiveInfinity, 1f, out nextPosition, out nextRotation) įinalize Movement public virtual void FinalizeMovement(Vector3 nextPosition, Quaternion nextRotation, Vector2d nextDirection)įinalizeRotation(nextRotation, nextDirection) įinalize Rotation void FinalizeRotation(Quaternion nextRotation, Vector2d nextDirection)įinalize Position void FinalizePosition(Vector3 nextPosition) Unknown, null path part, or the character is stopped. TraverseFunnel(funnel, deltaTime, out nextPosition, out nextRotation) NornRichFunnel funnel = currentPart as NornRichFunnel NextPosition = steeringTarget = simulatedPosition StartCoroutine(TraverseSpecial(currentPart as NornRichSpecial)) NornRichPathPart currentPart = richPath.GetCurrentPart() MovementUpdateInterval protected override void MovementUpdateInternal(float deltaTime, out Vector3 nextPosition, out Quaternion nextRotation) Return movementPlane.ToPlane(simulatedRotation * Vector3.forward) Quaternion simulatedRotation updates the gameObject's transform.rotation, and is updated indirectly via the "nextRotation" out variables of the functions mentioned, in which the class SimulateRotationTowards is invoked.ĬalculateVector2Forward private Vector2 CalculateVector2Forward() These are both invoked from MovementUpdateInterval function. This all exists as part of a complex solution. I extracted this into the function CalculateVector2Forward, which is invoked inside TraverseFunnel and FinalMovement. There are two functions which use Quaternion * Vector calculations which need replaced.
Unity forward vector 2d code#
I do not have a deterministic quaternion class, and the deterministic code I have found elsewhere uses a deterministic Vector2 to store rotation data instead of a Quaternion. The problem is that there are some operations which use quaternion times vector calculations. I'm just in the process of replacing the data types with deterministic vector classes. There are custom vector classes I have picked up elsewhere which use longs instead of floats to store position data deterministicly. It has to be deterministic, so I'm editing a pathfinding library which uses floating point based classes (this is with Unity) like Vector2, Vector3, Quaternion. I am working on local avoidance and pathfinding code for a 3D strategy game. Edit: Having to edit this question extensively because DMGregory was right and there were unexpected consequences.
