# How to do this works on mobile?

As you can see down, my character move constantly and rotate if i press button:

``````{
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
transform.position += transform.right * speed * Time.deltaTime;
``````

I’d like to know what to change on it to the player rotate the character touching screen(moving according to the finger slipping).

Bump

Please don’t bump more than once every 24 hours, and if it’s not of extreme importance waiting even longer between bumps would be greatly appreciated by the community.

To get you started on the solution, I’ll point you to the scripting reference entries of Input.getTouch and Input.touchCount.

Do you know what to change in this line?

``````transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
``````

I should change “GetAxis” for “Touch”. What else?

To know how far the finger moved, you’d want to know the Touch’s deltaPosition.

I changed the code to this:

``````if (Input.touchCount > 0  Input.GetTouch(0).phase == TouchPhase.Moved) {
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
transform.Rotate(0, touchDeltaPosition.y * rotateSpeed, 0);
}
``````

Does this code Works? I can’t test here.

The horizontal equivalent would be touchDeltaPosition.x.

Other than that, yes it should work.

Just out of curiosity: I’d like the character rotate in the Y axis.

So the right code is:

``````if (Input.touchCount > 0  Input.GetTouch(0).phase == TouchPhase.Moved) {
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
transform.Rotate.y(0, touchDeltaPosition.x * rotateSpeed, 0);
}
``````

Not quite.

It’s rotating on the y axis because you placed the value in the second parameter (the parameters are (x,y,z)).

Correct Code:

``````if (Input.touchCount > 0  Input.GetTouch(0).phase == TouchPhase.Moved) {
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
transform.Rotate (0, touchDeltaPosition.x * rotateSpeed, 0);
}
``````

Nice guy. Thanks!

Noticed I made a little mistake (my posts have been edited to reflect) you don’t need to multiply the rotation by Time.deltaTime as using the touch’s deltaPosition already makes it framerate independent.