I want to apply constant force to game object which has rigid body attached.
But I found that after applying continuous force to game object, game object’s speed increased per frame. That I have checked through printing velocity of game object.
I have used following code.
private Vector2 force;
public float speed, downLimit;
void Start ()
{
force = new Vector2 (speed, 0f);
}
void FixedUpdate ()
{
rigidbody2D.AddForce (force);
print ("bird velocity : " + rigidbody2D.velocity);
CheckForDownLimit ();
}
private void CheckForDownLimit ()
{
Vector3 birdPosition = transform.position;
if (birdPosition.y < downLimit * -1f) {
force.y = speed * Constants.VERTICLE_SPEED;
} else if (birdPosition.y > downLimit) {
force.y = -speed * Constants.VERTICLE_SPEED;
} else {
force.y = 0;
}
}
I want to move my game object with same speed at any level of game not with continuous increasing speed.