PhysicsBody2D
The base class for 2D physics bodies.
PhysicsBody2D provides body operations and MoveAndCollide motion queries. Use CharacterBody for controlled characters, RigidBody for forces/impulses and StaticBody for walls.
MoveAndCollide tests distance displacement, returns a contact or null and supports testOnly without movement. Its result does not automatically slide or reflect. GetGravity provides the applicable field; applying it to character velocity remains your logic.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Methods6
AddCollisionExceptionWithvoid
public void AddCollisionExceptionWith(Entity body);Adds a body to the list of bodies that this body can't collide with.
| Name | Type | Default |
|---|---|---|
body | Entity | — |
GetCollisionExceptionsReckfell.Collections.Array<PhysicsBody2D>
public Reckfell.Collections.Array<PhysicsBody2D> GetCollisionExceptions();Returns an array of nodes that were added as collision exceptions for this body.
Reckfell.Collections.Array<PhysicsBody2D>GetGravityVector2
public Vector2 GetGravity();Returns the gravity vector computed from all sources that can affect the body, including all gravity overrides from Area2D nodes and the global world gravity.
Vector2MoveAndCollideKinematicCollision2D
public KinematicCollision2D MoveAndCollide(Vector2 motion, bool testOnly = false, float safeMargin = 0.08f, bool recoveryAsCollision = false);Tests displacement for this call, usually velocity × delta. Returns KinematicCollision or null. testOnly does not move the body; define subsequent sliding/reflection separately.
| Name | Type | Default |
|---|---|---|
motion | Vector2 | — |
testOnly | bool | false |
safeMargin | float | 0.08f |
recoveryAsCollision | bool | false |
KinematicCollision2DRemoveCollisionExceptionWithvoid
public void RemoveCollisionExceptionWith(Entity body);Removes a body from the list of bodies that this body can't collide with.
| Name | Type | Default |
|---|---|---|
body | Entity | — |
TestMovebool
public bool TestMove(Transform2D from, Vector2 motion, KinematicCollision2D collision = null, float safeMargin = 0.08f, bool recoveryAsCollision = false);Checks for collisions without moving the body. In order to be frame rate independent in Entity._PhysicsProcess or Entity._Process, motion should be computed using delta.
Virtually sets the node's position, scale and rotation to that of the given Transform2D, then tries to move the body along the vector motion. Returns true if a collision would stop the body from moving along the whole path.
collision is an optional object of type KinematicCollision2D, which contains additional information about the collision when stopped, or when touching another body along the motion.
safe_margin is the extra margin used for collision recovery (see CharacterBody2D.SafeMargin for more details).
If recovery_as_collision is true, any depenetration from the recovery phase is also reported as a collision; this is useful for checking whether the body would touch any other bodies.
| Name | Type | Default |
|---|---|---|
from | Transform2D | — |
motion | Vector2 | — |
collision | KinematicCollision2D | null |
safeMargin | float | 0.08f |
recoveryAsCollision | bool | false |
bool