To apply a constant linear or rotational force to a GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary’s RigidbodyA component that allows a GameObject to be affected by simulated gravity and other forces. More info
See in Glossary, add the Constant ForceA simple component for adding a constant force or torque to game objects with a Rigidbody. More info
See in Glossary component (represented by the API class ConstantForce
) to your GameObject. See Constant Force component reference for details on how to configure the properties on the component.
Constant force is not the same as constant speed. When you apply a constant force, the speed of movement accelerates over time based on the value of the force. In real life, this acceleration continues indefinitely. By default in Unity’s physics simulation, linear acceleration continues indefinitely, and angular acceleration continues until the Rigidbody reaches a max velocity of 50 rad/s. You can change these maximum velocities in code, via the properties Rigidbody.maxLinearVelocity
and Rigidbody.maxAngularVelocity
.
To make a GameObject constantly accelerate forward (for example, to make it behave like a rocket), do the following:
Add a Constant Force component to the GameObject. On the Constant Force component, set the Relative Force Z axis to a positive value. On the Rigidbody, disable Use Gravity*. This ensures that there is no competing gravitational force acting upon the GameObject. On the Rigidbody component, set the Drag** property so that the Rigidbody does not exceed your preferred maximum velocity (the higher the drag, the lower the maximum velocity will be). This might require some trial and error to get the effect you want.