Unity forward vector 2d1/1/2024 ![]() 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. John Pan's Lockstep Framework (deterministic).Aron Granberg's A* Pathfinding Project (non-deterministic).I suppose there's no reason to calculate it in 3D, as that's just added complexity, elevation gets tagged on later. This is fine, because the pathfinding and avoidance library converts Vector3 to Vector2, to calculate avoidance on a 2D plane. public static Vector2d CreateRotation(long angle) 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. ![]() But when I then try and add a force in the forward or backward direction, the object is not moving in the object's local forward direction, but instead, in the same forward direction as before.Edit: Having to edit this question extensively because DMGregory was right and there were unexpected consequences. I then use the left arrow key to rotate the object left, which also works. ![]() Here is a gif of what happens.Īs you can see, initially, moving forward and backward using the up and down arrow keys works. Rotating left and right seems to work, but moving forwards and backwards seems to only work in the world coordinate space for some reason. Also, The left and right arrows should simply rotate the player-object (changing the forward direction in its local coordinate space). I would expect for this code to make my Player object move forward in its local coordinate space when I hold the up-arrow on the keyboard, and move backward in the same space when I hold the down-arrow. Start is called before the first frame updateĭebug.Log(string.Format("Transform.rotation is ", )) ĭebug.DrawRay(transform.position, transform.forward, Color.yellow) ĬarRigidbody.AddRelativeForce(transform.forward * 10) ĬarRigidbody.AddRelativeForce(transform.forward * -10) Public class PlayerScript : MonoBehaviour Here is this script: using System.Collections I have a Player object, which looks like this:Īs you can see, I have a Rigidbody2d component attached to this object, as well as a script, called "PlayerScript". I am building a very simple car-driving game in Unity.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |