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
Share
Go down
avatar
Member [Lv. 1]
Member [Lv. 1]
Posts : 3
Points : 575
Rep : 0
Join date : 2017-01-14
View user profile

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

on Sat Jan 14, 2017 8:11 pm
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);
 }
 }
avatar
Moderator
Moderator
Posts : 76
Points : 1927
Rep : 16
Join date : 2014-06-02
Age : 15
Location : Milky Way
View user profile

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

on Sun Jan 15, 2017 9:29 am
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.
avatar
Member [Lv. 1]
Member [Lv. 1]
Posts : 3
Points : 575
Rep : 0
Join date : 2017-01-14
View user profile

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

on Sun Jan 15, 2017 9:37 am
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.
avatar
Moderator
Moderator
Posts : 76
Points : 1927
Rep : 16
Join date : 2014-06-02
Age : 15
Location : Milky Way
View user profile

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

on Sun Jan 15, 2017 12:50 pm
Maybe this will help? http://answers.unity3d.com/questions/857868/smooth-transformtranslate-movement.html
avatar
Member [Lv. 1]
Member [Lv. 1]
Posts : 3
Points : 575
Rep : 0
Join date : 2017-01-14
View user profile

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

on Mon Jan 16, 2017 7:03 pm
DeveloperLuke wrote:Maybe this will help? http://answers.unity3d.com/questions/857868/smooth-transformtranslate-movement.html

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);
 
 }
 
avatar
Moderator
Moderator
Posts : 76
Points : 1927
Rep : 16
Join date : 2014-06-02
Age : 15
Location : Milky Way
View user profile

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

on Tue Jan 17, 2017 11:05 pm
No problem!
Glad to see you got it working! Very Happy
Back to top
Permissions in this forum:
You cannot reply to topics in this forum