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 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
// 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.
Answer by Nehrk
Mar 14 at 08:01 AM
See this. link Using DOTween path and other plugins can help you make this much faster.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
5 People are following this question.
Confusion trying to set position at an angle
Character movement that ends with a specific facing
Why does this affect the rotation.z
How do I adjust code so gyro translates player to center position when device is being held in hands
Moving forward based off of Rotation