Scripting API

Rigidbody2D

class in UnityEngine · UnityEngine.Physics2DModule · inherits from Component

58 of 63 of Unity's membersUnity's documentation
In Tassix

A Box2D body (see tassix_physics2d). Settings push to the native body immediately; position, rotation and velocities read the simulation. Angles are in degrees, as in Unity. Defaults are Unity 6's.

Properties 30

float angularDamping { get; set; }
float angularDrag { get; set; }

Unity's pre-6 name for angularDamping.

float angularVelocity { get; set; }

Degrees per second.

int attachedColliderCount { get; }
RigidbodyType2D bodyType { get; set; }
Vector2 centerOfMass { get; set; }
CollisionDetectionMode2D collisionDetectionMode { get; set; }
RigidbodyConstraints2D constraints { get; set; }
float drag { get; set; }

Unity's pre-6 name for linearDamping.

LayerMask excludeLayers { get; set; }
bool freezeRotation { get; set; }
float gravityScale { get; set; }
LayerMask includeLayers { get; set; }
float inertia { get; set; }

Mass and inertia scale the colliders' distribution to mass.

RigidbodyInterpolation2D interpolation { get; set; }

Stored; rendering interpolation arrives with render-side transform smoothing.

bool isKinematic { get; set; }

Unity's older switch between Kinematic and Dynamic.

float linearDamping { get; set; }
Vector2 linearVelocity { get; set; }
float linearVelocityX { get; set; }
float linearVelocityY { get; set; }
float mass { get; set; }
Vector2 position { get; set; }

The body's position in the simulation (the transform follows after the next step).

float rotation { get; set; }

Degrees about Z.

PhysicsMaterial2D? sharedMaterial { get; set; }

The material for attached colliders without their own.

bool simulated { get; set; }
RigidbodySleepMode2D sleepMode { get; set; }
bool useAutoMass { get; set; }
bool useFullKinematicContacts { get; set; }
Vector2 velocity { get; set; }

Unity's pre-6 name for linearVelocity.

Vector2 worldCenterOfMass { get; }

Methods 32

void AddForce(Vector2 force, ForceMode2D mode = ForceMode2D.Force)
void AddForce(Vector2 force)
void AddForceAtPosition(Vector2 force, Vector2 position, ForceMode2D mode = ForceMode2D.Force)
void AddForceAtPosition(Vector2 force, Vector2 position)
void AddForceX(float force, ForceMode2D mode = ForceMode2D.Force)
void AddForceY(float force, ForceMode2D mode = ForceMode2D.Force)
void AddRelativeForce(Vector2 relativeForce, ForceMode2D mode = ForceMode2D.Force)
void AddRelativeForce(Vector2 relativeForce)
void AddRelativeForceX(float force, ForceMode2D mode = ForceMode2D.Force)
void AddRelativeForceY(float force, ForceMode2D mode = ForceMode2D.Force)
void AddTorque(float torque, ForceMode2D mode = ForceMode2D.Force)
void AddTorque(float torque)
int Cast(Vector2 direction, RaycastHit2D[] results, float distance = float.PositiveInfinity)
int Cast(Vector2 direction, RaycastHit2D[] results)
int Cast(Vector2 direction, ContactFilter2D contactFilter, RaycastHit2D[] results, float distance = float.PositiveInfinity)
int Cast(Vector2 direction, ContactFilter2D contactFilter, RaycastHit2D[] results)
int Cast(Vector2 direction, List<RaycastHit2D> results, float distance = float.PositiveInfinity)
int Cast(Vector2 direction, ContactFilter2D contactFilter, List<RaycastHit2D> results, float distance = float.PositiveInfinity)
Vector2 ClosestPoint(Vector2 position)

The point on the body's colliders closest to position.

ColliderDistance2D Distance(Collider2D collider)

The smallest distance from the body's colliders to collider.

int GetAttachedColliders(List<Collider2D> results)
int GetAttachedColliders(Collider2D[] results)
int GetContacts(ContactPoint2D[] contacts)
int GetContacts(List<ContactPoint2D> contacts)
int GetContacts(ContactFilter2D contactFilter, ContactPoint2D[] contacts)
int GetContacts(ContactFilter2D contactFilter, List<ContactPoint2D> contacts)
int GetContacts(Collider2D[] colliders)
int GetContacts(List<Collider2D> colliders)
int GetContacts(ContactFilter2D contactFilter, Collider2D[] colliders)
int GetContacts(ContactFilter2D contactFilter, List<Collider2D> colliders)
Vector2 GetPoint(Vector2 point)

A local point in world space, by the body's pose.

Vector2 GetPointVelocity(Vector2 point)
Vector2 GetRelativePoint(Vector2 relativePoint)
Vector2 GetRelativePointVelocity(Vector2 relativePoint)
Vector2 GetRelativeVector(Vector2 relativeVector)
Vector2 GetVector(Vector2 vector)
bool IsAwake()
bool IsSleeping()
bool IsTouching(Collider2D collider)
bool IsTouchingLayers(int layerMask = Physics2D.AllLayers)
bool IsTouchingLayers()
void MovePosition(Vector2 position)
void MovePositionAndRotation(Vector2 position, float angle)
void MovePositionAndRotation(Vector2 position, Quaternion rotation)
void MoveRotation(float angle)
void MoveRotation(Quaternion rotation)
int Overlap(ContactFilter2D contactFilter, Collider2D[] results)
int Overlap(ContactFilter2D contactFilter, List<Collider2D> results)
int Overlap(List<Collider2D> results)
bool OverlapPoint(Vector2 point)
void SetRotation(float angle)
void SetRotation(Quaternion angle)
void Sleep()
SlideResults Slide(Vector2 velocity, float deltaTime, SlideMovement slideMovement)

Moves the body by velocity over deltaTime, sliding along surfaces no steeper than surfaceSlideAngle (from surfaceUp) for up to maxIterations casts, then by gravity unless it rests on a surface no steeper than gravitySlipAngle. Casts use the body's colliders (or the selected one) and stop just short of what they hit (past both shapes' contact offsets).

void WakeUp()

Not in Tassix yet 5

GetShapes Slide localToWorldMatrix totalForce totalTorque

Checked against Unity

Conformance scenarios that exercise it, recorded in Unity and compared event by event.