How to make a turn like the Temple Run and NO THING ?
Now I create a game like the Temple Run and NO THING(store.steampowered.com/app/444800/) .
But I don't know to create a turn motion like the Temple Run to player. For example, press a key to turn left, d key to turn right.
Please help me:/
Answer by Robert_s_a · Mar 14, 2017 at 05:21 AM
I've never played Temple Run, but from your question, I think this is what you are looking for...
Unless you've changed it from the default settings, there is a Input.GetAxis("Horizontal") command which will read the A and D keys (also the left and right arrow keys) and return a positive number for D and right arrow, or a negative number for A and left arrow. You can use this to apply a rotation to your player.
There's also a Input.GetAxis("Vertical") function which reads the W and S, and up arrow and down arrow keys, which is often used for moving forward and backward - I'll leave that for you to play with.
The rotation part can be done something like this...
private float rotation;
private float rotationInput;
private float rotationSensitivity = 10.0f; // Adjust how quickly the player turns
private Quaternion rotationAngle; // This is what Unity uses to handle rotation
private Update()
{
// read keyboard input for horizontal axis
rotationInput = Input.GetAxis("Horizontal");
// adjust it based on the required sensitivity
rotation = rotationInput * rotationSensitivity;
// Convert the value to a rotational angle
rotationAngle = Quaternion.Euler(0.0f, rotation, 0.0f);
// Apply the rotation to your player object
transform.rotation = rotationAngle;
}
Depending on how you have your player set up, you may need to make the rotationSensitivity a negative number if you find that the player is turning the wrong direction.
I hope this helps.