- Home /
Choppy Character Movement Unity 2D
I am new to game development and have been following a tutorial to get started, it is a flappy bird style game. My main issue at the moment is when tapping the screen to move my character it is randomly choppy. I am running the game on Samsung Galaxy S5 so performance shouldn't be a major issue espcially for an extremely simple 2D style game. Here is the code I am using to control my character:
 public class GhostMovement : MonoBehaviour {
 
 Vector3 velocity = Vector3.zero;
 public float floatSpeed    = 100f;
 public float forwardSpeed = 1f;
 
 bool didFloat = false;
 
 Animator animator;
 
 public bool dead = false;
 float deathCooldown;
 
 // Use this for initialization
 void Start () {
     animator = transform.GetComponentInChildren<Animator>();        
 }
 
 // Do Graphic & Input updates here
 void Update() {
     if(dead) {
         deathCooldown -= Time.deltaTime;
 
         if(deathCooldown <= 0) {
             if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
                 Application.LoadLevel( Application.loadedLevel );
             }
         }
     }
     else {
         if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
             didFloat = true;
         }
     }
 }
 
 
 // Do physics engine updates here
 void FixedUpdate () {
 
     if(dead)
         return;
 
     rigidbody2D.AddForce( Vector2.right * forwardSpeed );
 
     if(didFloat) {
         rigidbody2D.AddForce( Vector2.up * floatSpeed );
         animator.SetTrigger("DoFloat");
         didFloat = false;
     }
 
     if(rigidbody2D.velocity.y > 0) {
         transform.rotation = Quaternion.Euler(0, 0, 0);
     }
     else {
         float angle = Mathf.Lerp (0, -90, (-rigidbody2D.velocity.y / 3f) );
         transform.rotation = Quaternion.Euler(0, 0, angle);
     }
 }
 
 void OnCollisionEnter2D(Collision2D collision) {
     animator.SetTrigger("Death");
     dead = true;
     deathCooldown = 0.5f;
 }
 }
If anyone could help me out I would greatly appreciate it. I have already played with vsync and turning interpolate on and off for my sprite and it doesn't seem to make a difference. It seems like when I tap the screen to move the character it will randomly skip a few frames so its not extremely smooth from point A to point B, if that makes any sense.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                