# Making my Game Object face according to direction of mobile joystick

Hey guys
I am making a footstep system for a game but i am facing a really weird issue with rotation.
i want to make my GameObjects rotation change to the direction where mobile joystick points but i cant really get it work

``````     private void Update()
{
Vector3 touchPosition = joy.transform.position;
footSteps.transform.eulerAngles = new Vector3(footSteps.transform.eulerAngles.x, Mathf.Atan2(touchPosition.y, touchPosition.x) * Mathf.Rad2Deg, footSteps.transform.eulerAngles.z);
}
``````

this is the code i am currently using.
i searched all the threads regarding this issue but none of the solutions worked

look at the video to know the result of this code.

just use the unity LookAt function. Something like this:

``````Vector3 touchPos = joy.transform.position;
footSteps.transform.LookAt(footSteps.transform.position + touchPos);
``````

EDIT:

Since your up Vector is not pointing in the looking direction this might not work. Also i have to admit that this isn’t the best solution because you probably only want to rotate the footsteps in one axis. However its the fastest to do. Here is another solution where you can specify the forward direction:

``````Vector3 stickPos = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f);
Vector3 lookingDir = Vector3.right;

if (stickPos != Vector3.zero) {
float angle = Vector3.Angle (lookingDir, stickPos);
if (Vector3.Cross (lookingDir, stickPos).z < 0f) {
angle = -angle;
}

transform.rotation = Quaternion.Euler (new Vector3 (0f, angle, 0f));
}
``````

you will have to change the stickPos to your joy position. If the player points in the wrong direction after that you might need to change the < 0f to >0f. I highly recommend to check the code instead of copying it and hope it works. Good luck

@look001 Didn’t work either
All what happened was the model got weirdly rotated on x axis