How do you rotate the player and keep them there?
I know this is probably something very simple I've just forgotten, but I'm trying to make the player able to rotate 180 degrees and stay there, but at the moment they are only rotated for as long as the key is pressed. This is what I have:
if (CrossPlatformInputManager.GetButton("Turn"))
{
transform.Rotate(Vector3.up, 180, Space.Self);
}
I wanted to make it so this happens smoothly in the space of about 1 second but I'd like to get the turning working first.
This is on the first person controller (albeit a slightly modified version, but nothing I've done would interfere with this) so it might be something on there that is messing it up. I've tried all kinds of things like different if statements, transforms and such even though the solution is probably much simpler than that. I am quite new to unity so pointers would be helpful.
Any help is appreciated :)
Answer by GuiDroid · Sep 01, 2017 at 05:01 PM
To make sure you only rotate once you should try:
(CrossPlatformInputManager.GetButtonDown("Turn")
instead of:
(CrossPlatformInputManager.GetButton("Turn")
The GetButton is true as long as the button is pressed, but the GetButtonDown is true only in the frame that the player pressed the button, more information here https://docs.unity3d.com/ScriptReference/Input.GetButton.html and here https://docs.unity3d.com/ScriptReference/Input.GetButtonDown.html
To make the player rotate smoothly you could use:
for(int i = 0; i < 45; i++)
{
transform.Rotate(Vector3.up, 4, Space.Self);
}
Sorry for the SUPER late reply but I have tried this and it only rotates the player for the signle frame that the button is pressed for