Quantcast
Channel: Questions in topic: "localeulerangles"
Viewing all articles
Browse latest Browse all 106

Problems rotating back to zero

$
0
0
Hi. I recently created a script that made the player lean with middle mouse click and drag. The problem that appears, is that the player does not rotate back to zero (on the Z axis). It rotates closer to 0, but still far from it. I get a different number every time. Here is the script causing this problem (sorry for the length): var leaning : boolean = false; var maximumLeft : float = -30; var maximumRight : float = 30; var currRotationZ : float = 0; var rotationSpeed : float = -5; var backToZeroSpeed : float = 2; var smoothDampVelocity : float; var maxSpeed : float = 5; var mouseLookObj1 : Transform; var mouseLookObj2 : Transform; function Update () { if(Input.GetMouseButton(2)){ leaning = true; if(mouseLookObj1){ mouseLookObj1.GetComponent(MouseLook).enabled = false; } if(mouseLookObj2){ mouseLookObj2.GetComponent(MouseLook).enabled = false; } currRotationZ += Input.GetAxis("Mouse X") * rotationSpeed; currRotationZ = Mathf.Clamp(currRotationZ, maximumLeft, maximumRight); transform.localEulerAngles.z = currRotationZ; }if(!Input.GetMouseButton(2)){ leaning = false; if(mouseLookObj1){ mouseLookObj1.GetComponent(MouseLook).enabled = true; } if(mouseLookObj2){ mouseLookObj2.GetComponent(MouseLook).enabled = true; } }if(!leaning){ currRotationZ = Mathf.SmoothDamp(currRotationZ, 0, smoothDampVelocity, backToZeroSpeed); transform.rotation.z = Mathf.SmoothDamp(transform.rotation.z, 0, smoothDampVelocity, backToZeroSpeed); } } Thanks, Luka.

Viewing all articles
Browse latest Browse all 106

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>