Hello. When a button is pressed, I want an object to rotate 120 degrees. Currently, the object rotares instantly, how can I have it take a few seconds? Here is my code so far. Thanks
if (Input.GetKeyDown("a")) {transform.Rotate (Vector3.up, -120);}
Hello. When a button is pressed, I want an object to rotate 120 degrees. Currently, the object rotares instantly, how can I have it take a few seconds? Here is my code so far. Thanks
if (Input.GetKeyDown("a")) {transform.Rotate (Vector3.up, -120);}
You can use a timer, or a coroutine, or (probably) iTween, or a state machine, or some combination of the above - there are lots of ways to solve the problem.
What solution will be optimal depends on the requirements. For example, what should happen if the user presses ‘a’ again while the object is rotating? So, the first step is probably to describe the desired behavior in more detail (either to yourself, which will help you in crafting an implementation, or here in this thread if you need more help with the problem).
When the player presses a, I would want the object to continue rotating. So, if the player rapidly pressed the button 4 times, the block would spin for a total of 480 degrees.
you can add a rotation force and up the drag it might be hard to combine them to exactly 120 degrees but that is the simpelest I can come up with for your problem