rob_vld
November 29, 2017, 3:23am
1
Hello !
I could really use your help on this, its giving me headaches…
Lets assume my character is going forward(local z) and facing local x
How would i calculate the horizontal/vertical input?
all we know is:
facing direction
previous and current position
Whatever your player’s orientation is (transform.rotation), you can rotate any Vector3 quantity by that orientation to achieve the new orientation.
In the above image, it appears your character is internally facing about Quaternion.Euler( 0, 90, 0).
If you want your character to be moving in Vector3( 0, 0, 1) (aka, Vector3.forward), then you can get the actual world vector by multiplying the Vector3 by the rotation (a quaternion):
Vector3 movementDesired = transform.rotation * Vector3.forward;
Where the transform is the transform of the rotated player object.
rob_vld
November 29, 2017, 4:26am
3
I am uncertain how to apply your suggestion to my code below
Could you throw me another hint please?
[parent]
— [characterMesh]
transform.position = Vector3.Lerp(transform.position, networkPosition, Time.deltaTime * 6f);
Vector3 moveInputs = ( positionPrevious - transform.position);
Vector3 relativeMoveDirection;
Vector3 characterRelativeMoveDirection;
relativeMoveDirection = Vector3.ProjectOnPlane(transform.TransformVector(new Vector3(moveInputs.x, 0, moveInputs.z)
), Vector3.up ) ;
characterRelativeMoveDirection = transform.InverseTransformDirection(
relativeMoveDirection.x,
relativeMoveDirection.y,
relativeMoveDirection.z).normalized ;
animator.SetFloat("Horizontal", -characterRelativeMoveDirection.x, 0.025f, Time.deltaTime * 0.5f);
animator.SetFloat("Vertical", -characterRelativeMoveDirection.z, 0.025f, Time.deltaTime * 0.5f);
mesh.transform.rotation = Quaternion.Lerp(mesh.transform.rotation
, Quaternion.Euler(0f, networkRotation, 0f)
, Time.deltaTime * 5f);
positionPrevious = transform.position;
rob_vld
December 12, 2017, 6:07pm
4
@Kurt-Dekker or anyone else?