Clamping the rotation of the steering wheel
I am using this code to clamp the rotation of the steering wheel, I want it to stop rotating if the z angle of the steering wheel is greater than 150 or less than 40 degrees but this code makes my steering wheel to rotate for an eternity, it doesnt even come to a halt. any help would be appreciated! Thanks using System.Collections;
public class TiltAround : MonoBehaviour { private Quaternion localRotation; // public float speed = 0.1f; // ajustable speed from Inspector in Unity editor
// Use this for initialization
void Start ()
{
// copy the rotation of the object itself into a buffer
localRotation = transform.rotation;
}
void Update() // runs 60 fps or so
{
// find speed based on delta
float curSpeed = Time.deltaTime * speed;
// // first update the current rotation angles with input from acceleration axis localRotation.z += Input.acceleration.x * curSpeed; localRotation.z = Mathf.Clamp (localRotation.z, 40, 150); //
//
// // then rotate this object accordingly to the new angle
transform.Rotate ( 0f, 0f,-localRotation.z);
//
}
}
Your answer
Follow this Question
Related Questions
Adding force to a rotating wheel using mouse or finger drag. 0 Answers
cannot rotate wheelcolliders in unity 5.3.1f1 4 Answers
Logitech Steering Wheel g920 does not work on PCs but on Laptops 0 Answers
car game unity 5 1 Answer
How can I make the character rotating the steering wheel inside the car? 0 Answers