So I know these things:
// var moveDirection:Vector3 = Raw movement direction input (Vertical and Horizontal axis).
// var up:Vector3 = Normal from face below me.
I have used cross products to figure it out, but I think there might be a faster way to accomplish this, since I am doing it every FixedUpdate, I’d like to do it as efficiently as possible, like some kind of a built in Vector3 method, that I just don’t know about ![]()
Here is how I have done it:
// Vector3.Cross(Vector3.Cross(localMoveDirection, -up), up);
// get the local forward direction based on input
var localMoveDirection:Vector3 = transform.TransformDirection(moveDireciton.normalized);
// get the local right axis
var localMoveRightAxis:Vector3 = Vector3.Cross(localMoveDirection, -up);
// use the right axis and up to determine the new direction
var newDir:Vector3 = Vector3.Cross(localMoveRightAxis, up);
So now newDir is movement direction along the face I am standing on.
Is there a better way to do this? Or is there a build in Unity function that does this, that I am too noob to recognize or know how to use?