- Home /
Move player in direction it's facing
Hi all
I'm developing a top-down shooter. I have the following situation. I have a virtual joystick which gives the current global direction to the player. It means that if the joystick is in direction (0, 0, 1), then the player will be directed to the same global direction, increasing the z value of its global position, independently by where its currently looking at. So if is looking back (0, 0, -1) and I give as input (0, 0, 1), it rotates and moves forward, so towards the direction (0, 0, 1).
Now, I need the following: I need that the if the player receives an input, e.g (0, 0, 1), it does not move forward globally, but forward respect to its current direction. So, for example, it is looking backward (0, 0, -1) and I give a forward input (0, 0, 1), it must move towards the direction (0, 0, -1). Otherwise, if I give the backward input (0, 0, -1) it must towards the direction (0, 0, 1).
How it can be done?
In this image, I provided an example.
Please, edit your question and provide your current code.
Use transform.Translate
to move a gameObject according to its current rotation