Hey guys, so i'm messing around with some simple 3D controls and I have run into an issue whereby the character will rotate at the last second after movement has stopped. This only tend to happen when is use a combination of WSAD controls. I was wondering whether this has something to do with the very last input taken at the end of a frame (so if I took my finger off W just before D then the character will snap right just at the end of movement instead of staying diagonal). This one has stumped me a bit with my current understanding of Vectors and was wondering if you guys have any solutions, Thanks. Code (CSharp): public class PlayerMovement : MonoBehaviour { public float speed = 10.0f; void Start() { } void Update() { float moveVertical = Input.GetAxis("Vertical"); float moveHorizontal = Input.GetAxis("Horizontal"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); transform.Translate(movement * speed * Time.deltaTime, Space.World); if(movement != Vector3.zero) { Quaternion LookRotation = Quaternion.LookRotation(movement); transform.rotation = LookRotation; } } }
Look into the input system(in the toolbar), when you release a key it doesn't go to 0 immideatly, you can change it with the 'gravity' setting on the axis.
This hasn't seemed to have fixed the issue. It seems like my player character will not stop in a diagonal position and will always snap to a angle of 90.