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
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_nameName of the method to check for.
Returns
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_nameName of the signal to check for.
Returns
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_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
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
Returns
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
Transform2Dmotion
Vector2collision
KinematicCollision2DsafeMargin
floatrecoveryAsCollision
bool