A Rigidbody2D component places an object under the control of the physics engine. Many concepts familiar from the standard Rigidbody component carry over to Rigidbody 2D, with the difference that in 2D, objects can only move in the XY plane and can only rotate on an axis perpendicular to that plane.
Property: | Function: |
---|---|
Mass | Mass of the rigidbody. |
Linear Drag | Drag coefficient affecting positional movement. |
Angular Drag | Drag coefficient affecting rotational movement. |
Gravity Scale | Degree to which the object is affected by gravity. |
Is Kinematic | Is the rigidbody moved by forces and collisions? |
Interpolate | How the object’s movement is interpolated between physics updates (useful when motion tends to be jerky). |
None | No movement smoothing is applied. |
Interpolate | Movement is smoothed based on the object’s positions in previous frames. |
Extrapolate | Movement is smoothed based on an estimate of its position in the next frame. |
Sleeping Mode | How the object “sleeps” to save processor time when it is at rest. |
Never Sleep | Sleeping is disabled (should be avoided where possible). |
Start Awake | Object is initially awake. |
Start Asleep | Object is initially asleep but can be woken by collisions. |
Collision Detection | How collisions with other objects are detected. |
Discrete | A collision is registered only if the object’s collider is in contact with another during a physics update. |
Continuous | A collision is registered if the object’s collider appears to have contacted another between updates. |
Constraints | Restrictions on the rigidbody’s motion:- |
Freeze Position | Stops the rigidbody moving in the world X & Y axes selectively. |
Freeze Rotation | Stops the rigidbody rotating around the Z axes selectively. |
Adding a Rigidbody 2D allows a sprite to be moved in a physically convincing way by applying forces from the scripting API. When the appropriate collider component is also attached to the sprite object, it will be affected by collisions with other moving objects. Using physics simplifies many common gameplay mechanics and allows for realistic, emergent behaviour with minimal coding.
Colliders define an approximate shape for an object that will be used by the physics engine to determine collisions with other objects. The collider types that can be used with Rigidbody 2D are the Circle Collider 2D, Box Collider 2D, Edge Collider 2D and Polygon Collider 2D - see the pages for these component for further details.
The Is Kinematic setting switches off the physical behaviour of the Rigidbody 2D so that it will not react to gravity and collisions. This is typically used to keep an object under non-physical script control most of the time but then switch to physics in a particular situation. For example, a player might normally move by walking (better handled without physics) but then get catapulted into the air by an explosion or strike. Physics can be used to create the catapulting effect if you switch off ’’Is Kinematic" just before applying a large force to the object.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.