Class: Rigidbody2DComponent
Unity's Rigidbody2D: puts the entity under 2D physics. Colliders on this entity and on its descendants (down to the next Rigidbody2D) form its shape. Physics2DSystem owns the body; it writes the simulated pose into the entity's world transform, and a Transform edit (a script, an animation) teleports a dynamic body or drives a kinematic one there.
Everything is in pixels and radians: positions px, velocities px/s, forces kg·px/s². Physics2DSettings.pixelsPerMeter maps them for the solver. Before the body exists (the first physics step after the component is added) velocity writes and forces are held and applied when it's created, so OnStart can launch it.
Extends
Constructors
Constructor
ts
new Rigidbody2DComponent(): Rigidbody2DComponent;Returns
Rigidbody2DComponent
Inherited from
Properties
| Property | Modifier | Type | Default value | Inherited from |
|---|---|---|---|---|
angularDamping | public | number | undefined | - |
bodyType | public | RigidbodyType2D | undefined | - |
collisionDetection | public | CollisionDetectionMode2D | undefined | - |
dirty | public | boolean | true | Component.dirty |
enabled | public | boolean | true | Component.enabled |
fixedRotation | public | boolean | undefined | - |
gravityScale | public | number | undefined | - |
interpolation | public | RigidbodyInterpolation2D | undefined | - |
linearDamping | public | number | undefined | - |
mass | public | number | undefined | - |
sleepMode | public | RigidbodySleepMode2D | undefined | - |
useAutoMass | public | boolean | undefined | - |
Accessors
actualMass
Get Signature
ts
get actualMass(): number;---- State ---- The simulated mass (kg) — mass, or the colliders' density × area with useAutoMass.
Returns
number
angularVelocity
Get Signature
ts
get angularVelocity(): number;Radians per second, counter-clockwise.
Returns
number
Set Signature
ts
set angularVelocity(w): void;Parameters
| Parameter | Type |
|---|---|
w | number |
Returns
void
inertia
Get Signature
ts
get inertia(): number;Kg·px² about the body's origin.
Returns
number
isSimulated
Get Signature
ts
get isSimulated(): boolean;The body exists — Play / Run is on, a 2D physics backend is set and a physics step has passed.
Returns
boolean
position
Get Signature
ts
get position(): PhysicsVec2;---- Pose (world space) ---- Where the body is, in world pixels — or where it will start.
Returns
rotation
Get Signature
ts
get rotation(): number;Returns
number
velocity
Get Signature
ts
get velocity(): PhysicsVec2;Returns
Set Signature
ts
set velocity(v): void;Parameters
| Parameter | Type |
|---|---|
v | PhysicsVec2 |
Returns
void
worldCenterOfMass
Get Signature
ts
get worldCenterOfMass(): PhysicsVec2;Returns
Methods
AddForce()
ts
AddForce(
fx,
fy,
mode?
): void;Parameters
| Parameter | Type | Default value |
|---|---|---|
fx | number | undefined |
fy | number | undefined |
mode | ForceMode2D | 'force' |
Returns
void
AddForceAtPosition()
ts
AddForceAtPosition(
fx,
fy,
px,
py,
mode?
): void;At a world point — off-centre, it spins the body too.
Parameters
| Parameter | Type | Default value |
|---|---|---|
fx | number | undefined |
fy | number | undefined |
px | number | undefined |
py | number | undefined |
mode | ForceMode2D | 'force' |
Returns
void
AddTorque()
ts
AddTorque(torque, mode?): void;Counter-clockwise, kg·px²/s² (or kg·px²/s as an impulse).
Parameters
| Parameter | Type | Default value |
|---|---|---|
torque | number | undefined |
mode | ForceMode2D | 'force' |
Returns
void
GetPointVelocity()
ts
GetPointVelocity(x, y): PhysicsVec2;Velocity (px/s) of a world point carried by the body.
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
IsAwake()
ts
IsAwake(): boolean;Returns
boolean
IsSleeping()
ts
IsSleeping(): boolean;Returns
boolean
MovePosition()
ts
MovePosition(x, y): void;A kinematic body travels there over the next step, pushing what's in the way (Unity MovePosition). A dynamic body is teleported.
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
void
MoveRotation()
ts
MoveRotation(angle): void;Parameters
| Parameter | Type |
|---|---|
angle | number |
Returns
void
SetVelocity()
ts
SetVelocity(x, y): void;Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
void
Sleep()
ts
Sleep(): void;Returns
void
Teleport()
ts
Teleport(
x,
y,
angle?
): void;Moves the body there at once, without sweeping through what's in between.
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
angle? | number |
Returns
void
WakeUp()
ts
WakeUp(): void;Returns
void