Question by
no00ob · Dec 23, 2018 at 10:42 PM ·
rotationtransformvector3quaternioneulerangles
Why isn't my steering wheel working?
I have created this steering wheel rotation script but it seems to be not working, first of all it snaps to the max angle on left side if I turn it left but smoothly rotates to the right, also it smoothly resets itself to 0 from the right side but does a weird 360 from the left side when it's supposed to reset. Any help? Oh also ignore that "rotations" variable it's not used anymore. Code:
void Update()
{
Vector3 vector = new Vector3(0, 310, 0);
//Debug.Log(wheel.transform.localEulerAngles.y);
if (rotations == 0)
{
wheel.transform.localRotation = defaultRotation;
}
if (wheel.transform.localEulerAngles.y <= 310)
{
if (InputController.Horizontal < 0)
{
wheel.transform.localEulerAngles = new Vector3(0, 310, 0);
}
}
if (wheel.transform.localEulerAngles.y >= 55)
{
if (InputController.Horizontal > 0)
{
wheel.transform.localEulerAngles = new Vector3(0, 55, 0);
}
}
if (InputController.Horizontal < 0)
{
wheel.transform.Rotate(-Vector3.up * Time.deltaTime * turnSpeed);
rotations -= turnSpeed;
}
else if (InputController.Horizontal > 0)
{
wheel.transform.Rotate(Vector3.up * Time.deltaTime * turnSpeed);
rotations += turnSpeed;
}
if (InputController.Horizontal == 0)
{
if (wheel.transform.localEulerAngles.y < 0)
{
Vector3 velocity = Vector3.zero;
wheel.transform.localEulerAngles = Vector3.SmoothDamp(-wheel.transform.localEulerAngles, new Vector3(0, -1, 0), ref velocity, 0.3f);
}
else
{
Vector3 velocity = Vector3.zero;
wheel.transform.localEulerAngles = Vector3.SmoothDamp(wheel.transform.localEulerAngles, new Vector3(0, 0, 0), ref velocity, 0.3f);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Quaternion rotation issue please help :'( 0 Answers
Rotation problem 0 Answers
How can I deal with eulers 1 Answer
Quaternion Rotation - AngleAxis/EulerAngle 2 Answers
How to use Quaternion.Slerp with transform.LookAt? 3 Answers