FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

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

more_horiz
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);
 }
 }

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

more_horiz
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.

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

more_horiz
@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.

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

more_horiz
Maybe this will help? http://answers.unity3d.com/questions/857868/smooth-transformtranslate-movement.html

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

more_horiz
@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);
 
 }
 

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

more_horiz
No problem!
Glad to see you got it working! Very Happy
Permissions in this forum:
You cannot reply to topics in this forum