Hi everyone,
I’m really new to this so bear with me ^^;
I have a car model I made with Maya which looks like this
The problem that I’m facing is rotating the front tires right and left, or should I say, limiting their Y rotation so they won’t go beyond 20 degree or something.
To avoid Gimbal lock, I’m using the Tire_FL_Nurbs and Tire_FR_Nurbs for that.
This is the script code I attached to both of them.
void Update ()
{
Debug.Log("y = "+ transform.rotation.y);
if (Input.GetKey(KeyCode.RightArrow))
{
if (transform.rotation.y < 0.2)
transform.Rotate(new Vector3(0f, 1f, 0f));
}
else
{
if (transform.rotation.y > 0)
{
transform.Rotate(new Vector3(0f, -1f, 0f));
}
}
if (Input.GetKey(KeyCode.LeftArrow))
{
if (transform.rotation.y > -0.2)
transform.Rotate(new Vector3(0f, -1f, 0f));
}
else
{
if (transform.rotation.y < 0)
{
transform.Rotate(new Vector3(0f, 1f, 0f));
}
}
}
Everything works fine when the car’s Y axis is 0. but when it changes, the code still try to make the tires look as if the car’s Y axis is still 0.
I’m not familiar with the concept, but I think that I need to use the car’s front Victor3. However, since the nurbs are children to the car’s body, doesn’t that mean I shouldn’t have to worry about this?
I’m using the Unity 4.1.3.