Table of Contents

Class PhysicsBody3D

Namespace
Godot
Assembly
GodotSharp.dll

PhysicsBody3D is an abstract base class for 3D game objects affected by physics. All 3D physics bodies inherit from it.

Warning: With a non-uniform scale, this node will likely not behave as expected. It is advised to keep its scale the same on all axes and adjust its collision shape(s) instead.

public class PhysicsBody3D : CollisionObject3D, IDisposable
Inheritance
PhysicsBody3D
Implements
Derived
Inherited Members

Properties

AxisLockAngularX

Lock the body's rotation in the X axis.

public bool AxisLockAngularX { get; set; }

Property Value

bool

AxisLockAngularY

Lock the body's rotation in the Y axis.

public bool AxisLockAngularY { get; set; }

Property Value

bool

AxisLockAngularZ

Lock the body's rotation in the Z axis.

public bool AxisLockAngularZ { get; set; }

Property Value

bool

AxisLockLinearX

Lock the body's linear movement in the X axis.

public bool AxisLockLinearX { get; set; }

Property Value

bool

AxisLockLinearY

Lock the body's linear movement in the Y axis.

public bool AxisLockLinearY { get; set; }

Property Value

bool

AxisLockLinearZ

Lock the body's linear movement in the Z axis.

public bool AxisLockLinearZ { get; set; }

Property Value

bool

Methods

AddCollisionExceptionWith(Node)

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

public void AddCollisionExceptionWith(Node body)

Parameters

body Node

GetCollisionExceptions()

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

public Array<PhysicsBody3D> GetCollisionExceptions()

Returns

Array<PhysicsBody3D>

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

MoveAndCollide(Vector3, bool, float, bool, int)

Moves the body along the vector motion. In order to be frame rate independent in _PhysicsProcess(double) or _Process(double), motion should be computed using delta.

The body will stop if it collides. Returns a KinematicCollision3D, which contains information about the collision when stopped, or when touching another body along the motion.

If testOnly is true, the body does not move but the would-be collision information is given.

safeMargin is the extra margin used for collision recovery (see SafeMargin for more details).

If recoveryAsCollision is true, any depenetration from the recovery phase is also reported as a collision; this is used e.g. by CharacterBody3D for improving floor detection during floor snapping.

maxCollisions allows to retrieve more than one collision result.

public KinematicCollision3D MoveAndCollide(Vector3 motion, bool testOnly = false, float safeMargin = 0.001, bool recoveryAsCollision = false, int maxCollisions = 1)

Parameters

motion Vector3
testOnly bool
safeMargin float
recoveryAsCollision bool
maxCollisions int

Returns

KinematicCollision3D

RemoveCollisionExceptionWith(Node)

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

public void RemoveCollisionExceptionWith(Node body)

Parameters

body Node

TestMove(Transform3D, Vector3, KinematicCollision3D, float, bool, int)

Checks for collisions without moving the body. In order to be frame rate independent in _PhysicsProcess(double) or _Process(double), 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.

safeMargin is the extra margin used for collision recovery (see SafeMargin for more details).

If recoveryAsCollision 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.

maxCollisions allows to retrieve more than one collision result.

public bool TestMove(Transform3D from, Vector3 motion, KinematicCollision3D collision = null, float safeMargin = 0.001, bool recoveryAsCollision = false, int maxCollisions = 1)

Parameters

from Transform3D
motion Vector3
collision KinematicCollision3D
safeMargin float
recoveryAsCollision bool
maxCollisions int

Returns

bool