I can’t seem to find out how to do this just right. My basic idea is that there is a lever that, when the key “e” is pressed, will rotate to give it the effect that it is activated. This is a 2D game, so the lever is a plane. I have a custom pivot point at the middle-bottom of the plane.
How can I rotate the object JUST to the left one time when the “e” key is pressed? I have tried multiple different options, but they all cause the plane to go in strange directions. The only one that has worked so far is:
function Update () {
if (Input.GetKey ("e") {
transform.Rotate (0, 45, 0 * Time.deltaTime, Space.World);
}
}
This did rotate the object gradually in the right direction as the “e” key was held, but this isn’t exactly the effect I’m going for. I want an automatic rotation, which will stop at a certain angle.
Any ideas? Help is greatly appreciated.
-myjean17
EDIT******************************************************
Well, I haven’t exactly solved my problem. So if anyone still wants to answer this question please do.
But I instead created an animation for the lever turning on and off, and tied them together and its actually functioning quite well.