Question by
SceneOfAction · Nov 28, 2021 at 08:03 AM ·
quaternioneulerrotaion
Locking lean rotation on a motorcycle.
I've done a bunch of searching but alas. When I lean left it's great, but when I lean right the bike snaps and goes haywire. Anyone with any tips would be greatly appreciated.
Code:
if(Input.GetAxis("Horizontal") !=0)
{
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + new Vector3(0f, 0f, -turnInput * turnAngleStrength * Time.deltaTime));
}
else
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, 0f), rotateSpeed * Time.deltaTime);
}
if(transform.rotation.eulerAngles.z >= 10f)
{
transform.eulerAngles = new Vector3 (transform.eulerAngles.x, transform.eulerAngles.y, 10f);
}
if(transform.rotation.eulerAngles.z <= -10f)
{
transform.eulerAngles = new Vector3 (transform.eulerAngles.x, transform.eulerAngles.y, -10f);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613045905im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Something seriously weird is going on with my transform.eulerAngles 0 Answers
Draw a ray from a gamobject and keep direction of the ray relative to the gameobjects rotation. 1 Answer
unwanted rotation in y axis 0 Answers
Child Object Rotation interpolation problem, 0 Answers
How do I set Transform.rotate to an absolute value? 1 Answer