Hello community!
I’ve got an object that swings from left to right using AddTorque.
Now, the real Machine has 3 buttons;
Button 1 = Swing left to right, no higher than 45 Degrees.
Button 2 = Swing left to right, no higher than 90 Degrees.
Button 3 = Swing left to right, no higher than 180 Degrees.
gameObject.AddComponent("HingeJoint");
hingeJoint.anchor = Vector3 (0,0,0);
hingeJoint.axis = Vector3.right;
function FixedUpdate () {
rigidbody.mass = 5;
rigidbody.drag = 0.05;
rigidbody.angularDrag = 0.05;
if (Input.GetKey("q")) {
rigidbody.AddTorque (0.2, 0, 0);
}else{
rigidbody.AddTorque (0, 0, 0);
}
if (Input.GetKey("e")) {
rigidbody.AddTorque (-0.2, 0, 0);
}else{
rigidbody.AddTorque (0, 0, 0);
}
}
As you can see, it pushes the object to the left with Q, and right with E, up to a full over-the-top rotation swing.
What I am looking for;
Press button ‘1’ (ONCE, not hold it)
Arm starts to swing with 0.2 Torque from left to right, until it reached its allowed swing height of 45 Degrees, and keeps swinging on that height, and NO higher.
Example video; http://www.youtube.com/watch?v=2smT3quuiRI
The movement is done automatically, just press either 1,2 or 3 and it off it goes!
Thanks in advance!!!