- Home /
Question by
JareBear12418 · May 19, 2018 at 03:45 AM ·
c#unity5controllerjoysticktopdown
How can I rotate my player to look at the direction my Joystick is pointing to? (Top-Down 2D)
How would i move the player Horizontally and vertically with joystick, with out rotating the player and move his rotated direction? like lets say i move joy stick down, the player goes down, if right, player moves right, not having to rotate player first, and then moving.
This is topdown 2D game.
Some one Please help me, I really need help.
Here is my code:
public class Player2Movement : MonoBehaviour { public float playerSpeed = 10; public float turnSpeed = 100;
void Update ()
{
float horizontal = Input.GetAxisRaw ("Horizontal");
float vertical = Input.GetAxisRaw ("Vertical");
transform.Translate (0f, vertical * Time.deltaTime * playerSpeed, 0f);
transform.Rotate (0f, 0f, horizontal * Time.deltaTime * turnSpeed);
}
}
Comment
Hey if your reading this, sorry about posting the same message twice thats my mistake, sorry about it
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How do you get the R1 and R2 buttons to work on the PS4? 0 Answers
C# Clamp joystick rotation 0 Answers
Distribute terrain in zones 3 Answers