Fire button click not always registered

I’m new to Unity, as you can see. I’m trying to create some test projects to learn and understand Unity3D. I’m in the 2D Stage right now.

I’m trying to create a falling character, which will move up and it will move to the right while clicking the fire button. You can use Flappy Bird’s movement control as an example. I’m trying to create that movement control/engine. My character falls down perfectly. I’m using a gravity scale of 1 in Rigidbody2D. However, moving up and to the right seems to not work with my code.

using UnityEngine;
using System.Collections;

public class BirdScript : MonoBehaviour

    //Moving direction
    public Vector2 direction = new Vector2(-1, 0);

    //Store the movement
    private Vector2 movement;

    // Update is called once per frame
    void Update()
        bool inputX = Input.GetButtonDown("Fire1");

        if (inputX)
            if (rigidbody2D.IsSleeping())

            movement = new Vector2(direction.x, 0);

    void FixedUpdate()
        // Apply movement to the rigidbody
        rigidbody2D.velocity = movement;


It does move to the right, but it won’t move up (if I change the second parameter ‘0’ to something else, it will, but it will keep going up). It also won’t stop moving to the right.

I assume this is because of the gravity AND an error in my code, or I’m missing something.

What is the problem and what would I need to use to do what I’d like the character to do?


You are assigning a value to movement but never set it back to zero. As such it sets velocity to that value on each FixedUpdate() from then on.

You may want to look into ApplyForce().