0
votes

I have a ball and I want to move it on the X axis, so, in the FixedUpdate method I added a force:

rigidbody2D.AddForce(Vector2.right * speed);

The ball's speed increases because of this code I wrote. I want to make this force to be constant, so the ball's speed not to increase. How can I do that? Thanks a lot!

1

1 Answers

1
votes

Applying a constant force will accelerate the object, because that's how real physics work:

Force = mass * acceleration

In your case, the resulting acceleration is:

Acceleration = Force / mass

If you want to set the object speed to be constant, you should modify the rigidBody's velocity:

http://docs.unity3d.com/ScriptReference/Rigidbody2D-velocity.html

Something like this:

rigidbody2D.velocity = new Vector2(speed, 0);