Version: Unity 6.1 Alpha (6000.1)
LanguageEnglish
  • C#

Rigidbody2D

class in UnityEngine

/

Inherits from:Component

/

Implemented in:UnityEngine.Physics2DModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Provides physics movement and other dynamics, and the ability to attach Collider2D to it.

The Rigidbody2D is a fundamental physics component that provides multiple simulation dynamics, such as Rigidbody2D.position and Rigidbody2D.rotation for pose control, and Rigidbody2D.linearVelocity and Rigidbody2D.angularVelocity for velocity control.

You can attach multiple Collider2D to a Rigidbody2D to detect collisions and provide a collision response when you set Rigidbody2D.bodyType to RigidbodyType2D.Dynamic.

Properties

angularDampingThe angular damping of the Rigidbody2D angular velocity.
angularVelocityAngular velocity in degrees per second.
attachedColliderCountReturns the number of Collider2D attached to this Rigidbody2D.
bodyTypeThe physical behaviour type of the Rigidbody2D.
centerOfMassThe center of mass of the rigidBody in local space.
collisionDetectionModeThe method used by the physics engine to check if two objects have collided.
constraintsControls which degrees of freedom are allowed for the simulation of this Rigidbody2D.
excludeLayersThe additional Layers that all Collider2D attached to this Rigidbody2D should exclude when deciding if a contact with another Collider2D should happen or not.
freezeRotationControls whether physics will change the rotation of the object.
gravityScaleThe degree to which this object is affected by gravity.
includeLayersThe additional Layers that all Collider2D attached to this Rigidbody2D should include when deciding if a contact with another Collider2D should happen or not.
inertiaThe Rigidbody's resistance to changes in angular velocity (rotation).
interpolationPhysics interpolation used between updates.
linearDampingThe linear damping of the Rigidbody2D linear velocity.
linearVelocityThe linear velocity of the Rigidbody2D represents the rate of change over time of the Rigidbody2D position in world-units.
linearVelocityXThe X component of the linear velocity of the Rigidbody2D in world-units per second.
linearVelocityYThe Y component of the linear velocity of the Rigidbody2D in world-units per second.
localToWorldMatrixThe transformation matrix used to transform the Rigidbody2D to world space.
massMass of the Rigidbody.
positionThe position of the rigidbody.
rotationThe rotation of the rigidbody.
sharedMaterialThe PhysicsMaterial2D that is applied to all Collider2D attached to this Rigidbody2D.
simulatedIndicates whether the rigid body should be simulated or not by the physics system.
sleepModeThe sleep state that the rigidbody will initially be in.
totalForceThe total amount of force that has been explicitly applied to this Rigidbody2D since the last physics simulation step.
totalTorqueThe total amount of torque that has been explicitly applied to this Rigidbody2D since the last physics simulation step.
useAutoMassShould the total rigid-body mass be automatically calculated from the [[Collider2D.density]] of attached colliders?
useFullKinematicContactsShould kinematic/kinematic and kinematic/static collisions be allowed?
worldCenterOfMassGets the center of mass of the rigidBody in global space.

Public Methods

AddForceApply a force to the rigidbody.
AddForceAtPositionApply a force at a given position in space.
AddForceXAdds a force to the X component of the Rigidbody2D.linearVelocity only leaving the Y component of the world space Rigidbody2D.linearVelocity untouched.
AddForceYAdds a force to the Y component of the Rigidbody2D.linearVelocity only leaving the X component of the world space Rigidbody2D.linearVelocity untouched.
AddRelativeForceAdds a force to the local space Rigidbody2D.linearVelocity. In other words, the force is applied in the rotated coordinate space of the Rigidbody2D.
AddRelativeForceXAdds a force to the X component of the Rigidbody2D.linearVelocity in the local space of the Rigidbody2D only leaving the Y component of the local space Rigidbody2D.linearVelocity untouched.
AddRelativeForceYAdds a force to the Y component of the Rigidbody2D.linearVelocity in the local space of the Rigidbody2D only leaving the X component of the local space Rigidbody2D.linearVelocity untouched.
AddTorqueApply a torque at the rigidbody's centre of mass.
CastAll the Collider2D shapes attached to the Rigidbody2D are cast into the Scene starting at each Collider position ignoring the Colliders attached to the same Rigidbody2D.
ClosestPointReturns a point on the perimeter of all enabled Colliders attached to this Rigidbody that is closest to the specified position.
DistanceCalculates the minimum distance of this collider against all Collider2D attached to this Rigidbody2D.
GetAttachedCollidersReturns all Collider2D that are attached to this Rigidbody2D.
GetContactsRetrieves all contact points for all of the Collider(s) attached to this Rigidbody.
GetPointGet a local space point given the point point in rigidBody global space.
GetPointVelocityThe velocity of the rigidbody at the point Point in global space.
GetRelativePointGet a global space point given the point relativePoint in rigidBody local space.
GetRelativePointVelocityThe velocity of the rigidbody at the point Point in local space.
GetRelativeVectorGet a global space vector given the vector relativeVector in rigidBody local space.
GetShapesGets all the PhysicsShape2D used by all Collider2D attached to the Rigidbody2D.
GetVectorGet a local space vector given the vector vector in rigidBody global space.
IsAwakeIs the rigidbody "awake"?
IsSleepingIs the rigidbody "sleeping"?
IsTouchingChecks whether the collider is touching any of the collider(s) attached to this rigidbody or not.
IsTouchingLayersChecks whether any of the collider(s) attached to this rigidbody are touching any colliders on the specified layerMask or not.
MovePositionMoves the rigidbody to position.
MovePositionAndRotationMoves the rigidbody position to position and the rigidbody angle to angle.
MoveRotationRotates the Rigidbody to angle (given in degrees).
OverlapGet a list of all Colliders that overlap all Colliders attached to this Rigidbody2D.
OverlapPointCheck if any of the Rigidbody2D colliders overlap a point in space.
SetRotationSets the rotation of the Rigidbody2D to angle (given in degrees).
SleepMake the rigidbody "sleep".
SlideSlide the Rigidbody2D using the specified velocity integrated over deltaTime using the configuration specified by slideMovement.
WakeUpDisables the "sleeping" state of a rigidbody.

Inherited Members

Properties

gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public Methods

BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentGets a reference to a component of type T on the same GameObject as the component specified.
GetComponentInChildrenGets a reference to a component of type T on the same GameObject as the component specified, or any child of the GameObject.
GetComponentIndexGets the index of the component on its parent GameObject.
GetComponentInParentGets a reference to a component of type T on the same GameObject as the component specified, or any parent of the GameObject.
GetComponentsGets references to all components of type T on the same GameObject as the component specified.
GetComponentsInChildrenGets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject.
GetComponentsInParentGets references to all components of type T on the same GameObject as the component specified, and any parent of the GameObject.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
TryGetComponentGets the component of the specified type, if it exists.
GetInstanceIDGets the instance ID of the object.
ToStringReturns the name of the object.

Static Methods

DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.
InstantiateAsyncCaptures a snapshot of the original object (that must be related to some GameObject) and returns the AsyncInstantiateOperation.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.