Quantcast
Viewing all articles
Browse latest Browse all 133

Quaternion.slerp messing with wrong axies

So I'm trying to write a script to rotate my sled between -10 and 10 degrees on the X axis when pressing the left and right arrow keys respectively. What currently happens is that the sled will flip entirely the wrong direction on the Y axis and begin to spiral out. I have been trying to figure this out for days, can anyone help? private void Start() { rb.transform.rotation = Quaternion.Euler(0, 180, 20); AngleL = Quaternion.Euler(-10, rb.rotation.y, rb.rotation.z); AngleR = Quaternion.Euler(10, rb.rotation.y, rb.rotation.z); Physics.gravity = new Vector3(0, -400f, 0); } void FixedUpdate() { transform.Translate(new Vector3(-moveSpeed,0,0) * Time.deltaTime); if(Input.GetAxis("Horizontal") > 0) { transform.Translate(new Vector3(0,0,turnSpeed) * Time.deltaTime); //anim.SetTrigger("Right"); currentAngle = AngleR; transform.rotation = Quaternion.Slerp(transform.rotation, currentAngle, 0.1f); } if (Input.GetAxis("Horizontal") < 0) { transform.Translate(new Vector3(0,0,-turnSpeed) * Time.deltaTime); currentAngle = AngleL; transform.rotation = Quaternion.Slerp(transform.rotation, currentAngle, 0.1f); } }

Viewing all articles
Browse latest Browse all 133

Trending Articles



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