Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » How to make my touch movements for Unity android game more smooth?

How to make my touch movements for Unity android game more smooth?

View previous topic View next topic Go down  Message [Page 1 of 1]

NoCodeMonkey

avatar
Member [Lv. 1]
Member [Lv. 1]
I have it set up for keyboard arrow keys and its smooth, but the code i implemented into my player script for touch movements isn't smooth (not sliding easily across the screen).  Question

Code:

void FixedUpdate(){
 if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Stationary) {
 Vector2 touchPosition = Input.GetTouch (0).position;
 double halfScreen = Screen.width / 2.0;

 if (touchPosition.x < halfScreen) {
 transform.Translate (Vector2.right * playerspeed * Time.deltaTime);
 } else if (touchPosition.x > halfScreen) {
 transform.Translate (Vector2.left * playerspeed * Time.deltaTime);
 }
 }

View user profile

DeveloperLuke

avatar
Moderator
Moderator
Are you using it in the editor? It might be because of the lag if you are. Try building it and see how that runs if you haven't already.

View user profile

NoCodeMonkey

avatar
Member [Lv. 1]
Member [Lv. 1]
DeveloperLuke wrote:Are you using it in the editor? It might be because of the lag if you are. Try building it and see how that runs if you haven't already.

Thanks for the tip but already tired that.

View user profile

DeveloperLuke

avatar
Moderator
Moderator

View user profile

NoCodeMonkey

avatar
Member [Lv. 1]
Member [Lv. 1]

Thanks for the link! Very Happy I did a bit more messing around with the help of that link and managed to get it working to how i needed it to bounce

Code:

void FixedUpdate(){


 if (Input.touchCount == 1)
 {
 if (Input.GetTouch (0).position.x < Screen.width / 2)
 {
 transform.Translate (Vector3.right * playerspeed * Time.deltaTime);
 
 }
 else if (Input.GetTouch (0).position.x > Screen.width / 2)
 {
 transform.Translate (Vector3.left * playerspeed * Time.deltaTime);
 
 }
 

View user profile

DeveloperLuke

avatar
Moderator
Moderator
No problem!
Glad to see you got it working! Very Happy

View user profile

Sponsored content


View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum