Table of Contents

Class PhysicsBody2D

Namespace
Godot
Assembly
GodotSharp.dll

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

public class PhysicsBody2D : CollisionObject2D, IDisposable
Inheritance
PhysicsBody2D
Implements
Derived
Inherited Members

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<PhysicsBody2D> GetCollisionExceptions()

Returns

Array<PhysicsBody2D>

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(Vector2, bool, float, bool)

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.

Returns a KinematicCollision2D, 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 CharacterBody2D for improving floor detection during floor snapping.

public KinematicCollision2D MoveAndCollide(Vector2 motion, bool testOnly = false, float safeMargin = 0.08, bool recoveryAsCollision = false)

Parameters

motion Vector2
testOnly bool
safeMargin float
recoveryAsCollision bool

Returns

KinematicCollision2D

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(Transform2D, Vector2, KinematicCollision2D, float, bool)

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

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.

public bool TestMove(Transform2D from, Vector2 motion, KinematicCollision2D collision = null, float safeMargin = 0.08, bool recoveryAsCollision = false)

Parameters

from Transform2D
motion Vector2
collision KinematicCollision2D
safeMargin float
recoveryAsCollision bool

Returns

bool