PhysicsBody3D
The base class for 3D physics bodies.
PhysicsBody3D 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.
Properties6
AxisLockAngularXProperty
public bool AxisLockAngularX { get; set; }Lock the body's rotation in the X axis.
AxisLockAngularYProperty
public bool AxisLockAngularY { get; set; }Lock the body's rotation in the Y axis.
AxisLockAngularZProperty
public bool AxisLockAngularZ { get; set; }Lock the body's rotation in the Z axis.
AxisLockLinearXProperty
public bool AxisLockLinearX { get; set; }Lock the body's linear movement in the X axis.
AxisLockLinearYProperty
public bool AxisLockLinearY { get; set; }Lock the body's linear movement in the Y axis.
AxisLockLinearZProperty
public bool AxisLockLinearZ { get; set; }Lock the body's linear movement in the Z axis.
Methods8
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 | — |
GetAxisLockbool
public bool GetAxisLock(PhysicsServer3D.BodyAxis axis);Returns true if the specified linear or rotational axis is locked.
| Name | Type | Default |
|---|---|---|
axis | PhysicsServer3D.BodyAxis | — |
boolGetCollisionExceptionsReckfell.Collections.Array<PhysicsBody3D>
public Reckfell.Collections.Array<PhysicsBody3D> GetCollisionExceptions();Returns an array of nodes that were added as collision exceptions for this body.
Reckfell.Collections.Array<PhysicsBody3D>GetGravityVector3
public Vector3 GetGravity();Returns the gravity vector computed from all sources that can affect the body, including all gravity overrides from Area3D nodes and the global world gravity.
Vector3MoveAndCollideKinematicCollision3D
public KinematicCollision3D MoveAndCollide(Vector3 motion, bool testOnly = false, float safeMargin = 0.001f, bool recoveryAsCollision = false, int maxCollisions = 1);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 | Vector3 | — |
testOnly | bool | false |
safeMargin | float | 0.001f |
recoveryAsCollision | bool | false |
maxCollisions | int | 1 |
KinematicCollision3DRemoveCollisionExceptionWithvoid
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 | — |
SetAxisLockvoid
public void SetAxisLock(PhysicsServer3D.BodyAxis axis, bool @lock);Locks or unlocks the specified linear or rotational axis depending on the value of lock.
| Name | Type | Default |
|---|---|---|
axis | PhysicsServer3D.BodyAxis | — |
lock | bool | — |
TestMovebool
public bool TestMove(Transform3D from, Vector3 motion, KinematicCollision3D collision = null, float safeMargin = 0.001f, bool recoveryAsCollision = false, int maxCollisions = 1);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 Transform3D, 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 KinematicCollision3D, 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 CharacterBody3D.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.
max_collisions allows to retrieve more than one collision result.
| Name | Type | Default |
|---|---|---|
from | Transform3D | — |
motion | Vector3 | — |
collision | KinematicCollision3D | null |
safeMargin | float | 0.001f |
recoveryAsCollision | bool | false |
maxCollisions | int | 1 |
bool