- Home /
Rotation with mouse instantly resets
I'm trying to get my player to rotate based on mouse movement (top down perspective, 3d game), but this ends up creating a really jerky motion that instantly resets my rotation back to zero. Not sure why this is happening - any help would be very appreciated!
void NewTurning()
{
float rot = Input.GetAxis("Mouse X") * rotSpeed * Time.deltaTime;
Quaternion newRotation = Quaternion.Euler(0, rot, 0);
transform.localRotation = newRotation;
}
Answer by highpockets · Jun 02, 2019 at 09:34 AM
You are setting the rotation always to pretty much the exact same value every time this code runs. I think you want to add to the existing rotation which would look like this:
Quaternion newRotation = transform.localRotation * Quaternion.Euler(0,rot,0);
That will add to your existing rotation
So, I guess that solved your question, can you mark it as the correct answer then?
Your answer
Follow this Question
Related Questions
My walking animations root motion has a problem when my mouse look script is being used? 0 Answers
How to reset position of an object after animation 1 Answer
3drd person camera reset 0 Answers
2D click movement not functtioning properly 0 Answers
How to incorporate a rotation towards mouse position in this script? I tried 0 Answers