reckfellENGINE

PhysicsBody2D

The base class for 2D physics bodies.

On this page
class PhysicsBody2DReckfellSharpInherits CollisionObject2D

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.

Working examples.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Methods6

AddCollisionExceptionWithvoid
# AddCollisionExceptionWith
C#
public void AddCollisionExceptionWith(Entity body);

Adds a body to the list of bodies that this body can't collide with.

Parameters
NameTypeDefault
bodyEntity—
GetCollisionExceptionsReckfell.Collections.Array<PhysicsBody2D>
# GetCollisionExceptions
C#
public Reckfell.Collections.Array<PhysicsBody2D> GetCollisionExceptions();

Returns an array of nodes that were added as collision exceptions for this body.

Returns Reckfell.Collections.Array<PhysicsBody2D>
GetGravityVector2
# GetGravity
C#
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.

Returns Vector2
MoveAndCollideKinematicCollision2D
# MoveAndCollide
C#
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.

Parameters
NameTypeDefault
motionVector2—
testOnlyboolfalse
safeMarginfloat0.08f
recoveryAsCollisionboolfalse
Returns KinematicCollision2D
RemoveCollisionExceptionWithvoid
# RemoveCollisionExceptionWith
C#
public void RemoveCollisionExceptionWith(Entity body);

Removes a body from the list of bodies that this body can't collide with.

Parameters
NameTypeDefault
bodyEntity—
TestMovebool
# TestMove
C#
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.

Parameters
NameTypeDefault
fromTransform2D—
motionVector2—
collisionKinematicCollision2Dnull
safeMarginfloat0.08f
recoveryAsCollisionboolfalse
Returns bool
Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.