A body that is controlled by the 2D physics engine.
|void||_integrate_forces ( Physics2DDirectBodyState state ) virtual|
|void||add_force ( Vector2 offset, Vector2 force )|
|void||apply_impulse ( Vector2 offset, Vector2 impulse )|
|Array||get_colliding_bodies ( ) const|
|void||set_axis_velocity ( Vector2 axis_velocity )|
|bool||test_motion ( Vector2 motion, float margin=0.08, Physics2DTestMotionResult result=null )|
Emitted when a body enters into contact with this one. Reports colliding shape information. See CollisionObject2D for shape index information. contact_monitor must be
true and contacts_reported greater than
Emitted when a body shape exits contact with this one. Reports colliding shape information. See CollisionObject2D for shape index information. contact_monitor must be
true and contacts_reported greater than
Emitted when sleeping changes.
-1the body will use the “Default Angular Damp” in “Project > Project Settings > Physics > 2d”. Default value:
truethe body will not calculate forces and will act as a static body if there is no movement. The body will wake up when other forces are applied via collisions or by using apply_impulse or add_force. Default value:
truethe body will emit signals when it collides with another RigidBody2D. See also contacts_reported. Default value:
Continuous collision detection tries to predict where a moving body will collide instead of moving it and correcting its movement after collision. Continuous collision detection is slower, but more precise and misses fewer collisions with small, fast-moving objects. Raycasting and shapecasting methods are available. See
CCD_MODE_ constants for details.
trueinternal force integration is disabled for this body. Aside from collision response, the body will only move as determined by the _integrate_forces function.
1(maximum friction). Default value:
-1the body will use the “Default Linear Damp” in “Project > Project Settings > Physics > 2d”. Default value:
MODE_*constants. Default value:
truethe body is sleeping and will not calculate forces until woken up by a collision or by using apply_impulse or add_force.
MODE_RIGID, but the body can not rotate.
This node implements simulated 2D physics. You do not control a RigidBody2D directly. Instead you apply forces to it (gravity, impulses, etc.) and the physics simulation calculates the resulting movement based on its mass, friction, and other physical properties.
A RigidBody2D has 4 behavior modes: Rigid, Static, Character, and Kinematic.
Note: You should not change a RigidBody2D’s
linear_velocity every frame or even very often. If you need to directly affect the body’s state, use _integrate_forces, which allows you to directly access the physics state.
If you need to override the default physics behavior, you can write a custom force integration. See custom_integrator.
Allows you to read and safely modify the simulation state for the object. Use this instead of Node._physics_process if you need to directly change the body’s
position or other physics properties. By default it works in addition to the usual physics behavior, but custom_integrator allows you to disable the default behavior and write custom force integration for a body.
Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
Applies a positioned impulse to the body (which will be affected by the body mass and shape). This is the equivalent of hitting a billiard ball with a cue: a force that is applied instantaneously. Both the impulse and the offset from the body origin are in global coordinates.
Returns a list of the bodies colliding with this one. Use contacts_reported to set the maximum number reported. You must also set contact_monitor to
true. Note that the result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead.
Sets the body’s velocity on the given axis. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
true if a collision would result from moving in the given vector.
margin increases the size of the shapes involved in the collision detection, and
result is an object of type Physics2DTestMotionResult, which contains additional information about the collision (should there be one).
© 2014–2018 Juan Linietsky, Ariel Manzur, Godot Engine contributors
Licensed under the MIT License.