Provides direct access to a physics body in the godot.Physics2DServer
, allowing safe changes to physics properties. This object is passed via the direct state callback of rigid/character bodies, and is intended for changing the direct state of that body. See godot.RigidBody2D._IntegrateForces
.
Variables
read onlytotalAngularDamp:Single
The rate at which the body stops rotating, if there are not any other forces moving it.
read onlytotalLinearDamp:Single
The rate at which the body stops moving, if there are not any other forces moving it.
Methods
addForce(offset:Vector2, force:Vector2):Void
Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
applyImpulse(offset:Vector2, impulse:Vector2):Void
Applies a positioned impulse to the body. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise). The offset uses the rotation of the global coordinate system, but is centered at the object's origin.
getContactColliderObject(contactIdx:Int):Object
Returns the collider object. This depends on how it was created (will return a scene node if such was used to create it).
getContactColliderShapeMetadata(contactIdx:Int):Dynamic
Returns the collided shape's metadata. This metadata is different from godot.Object.getMeta
, and is set with godot.Physics2DServer.shapeSetData
.
getContactColliderVelocityAtPosition(contactIdx:Int):Vector2
Returns the linear velocity vector at the collider's contact point.
getContactCount():Int
Returns the number of contacts this body has with other bodies.
Note: By default, this returns 0 unless bodies are configured to monitor contacts. See godot.RigidBody2D.contactMonitor
.
getSpaceState():Physics2DDirectSpaceState
Returns the current state of the space, useful for queries.
getVelocityAtLocalPosition(localPosition:Vector2):Vector2
Returns the body's velocity at the given relative position, including both translation and rotation.