-
Notifications
You must be signed in to change notification settings - Fork 0
class_rigidbody2d
####Inherits: PhysicsBody2D ####Category: Core
Rigid body 2D node.
- void
_integrate_forces( Physics2DDirectBodyState state ) virtual - void
set_mode( int mode ) -
int
get_mode( ) const - void
set_mass( real mass ) -
real
get_mass( ) const - void
set_weight( real weight ) -
real
get_weight( ) const - void
set_friction( real friction ) -
real
get_friction( ) const - void
set_bounce( real bounce ) -
real
get_bounce( ) const - void
set_linear_velocity( Vector2 linear_velocity ) -
Vector2
get_linear_velocity( ) const - void
set_angular_velocity( real angular_velocity ) -
real
get_angular_velocity( ) const - void
set_max_contacts_reported( int amount ) -
int
get_max_contacts_reported( ) const - void
set_use_custom_integrator( bool enable ) -
bool
is_using_custom_integrator( ) - void
set_contact_monitor( bool enabled ) -
bool
is_contact_monitor_enabled( ) const - void
set_use_continuous_collision_detection( bool enable ) -
bool
is_using_continuous_collision_detection( ) const - void
set_axis_velocity( Vector2 axis_velocity ) - void
apply_impulse( Vector2 pos, Vector2 impulse ) - void
set_applied_force( Vector2 force ) -
Vector2
get_applied_force( ) const - void
set_active( bool active ) -
bool
is_active( ) const - void
set_can_sleep( bool able_to_sleep ) -
bool
is_able_to_sleep( ) const
-
body_enter( Object body ) -
body_enter_shape( int body_id, Object body, int body_shape, int local_shape ) -
body_exit( Object body ) -
body_exit_shape( int body_id, Object body, int body_shape, int local_shape )
- MODE_STATIC = 1 - Static mode (does not move, can't be moved).
- MODE_KINEMATIC = 3
- MODE_RIGID = 0 - Rigid body, can move and rotate.
- MODE_CHARACTER = 2 - Character body, can move but not rotate.
Rigid body 2D node. This node is used for placing rigid bodies in the scene. It can contain a number of shapes, and also shift state between regular Rigid Body to Character or even Static. Character mode forbids the node from being rotated. This node can have a custom force integrator function, for writing complex physics motion behavior per node.
As a warning, don't change this node position every frame or very often. Sporadic changes work fine, but physics runs at a different granularity (fixed hz) than usual rendering (process callback) and maybe even in a separate thread, so changing this from a process loop will yield strange behavior.
- void
_integrate_forces( Physics2DDirectBodyState state ) virtual
Override this function to use a custom force integrator. This allows to hook up to the physics processing and alter the simulation state for the object on every frame.
- void
set_mode( int mode )
Set the body mode, fromt he MODE_* enum. This allows to change to a static body or a character body.
-
int
get_mode( ) const
Return the current body mode, see [set_mode].
- void
set_mass( real mass )
Set the body mass.
-
real
get_mass( ) const
Return the body mass.
- void
set_weight( real weight )
Set the body mass given standard earth-weight (gravity 9.8). Not really useful for 2D since most measuers for this node are in pixels.
-
real
get_weight( ) const
Return the body mass given standard earth-weight (gravity 9.8).
- void
set_friction( real friction )
Set the body friction, from 0 (friction less) to 1 (full friction).
-
real
get_friction( ) const
Return the body friction.
- void
set_bounce( real bounce )
Set the body bounciness, from 0 (no bounce) to 1 (bounce).
-
real
get_bounce( ) const
Return the body bouncyness.
- void
set_linear_velocity( Vector2 linear_velocity )
Set the body linear velocity. Can be used sporadically, but** DONT SET THIS IN EVERY FRAME **, because physics may be running in another thread and definitely runs at a different granularity. Use [_integrate_forces] as your process loop if you want to have precise control of the body state.
-
Vector2
get_linear_velocity( ) const
Return the body linear velocity. This changes by physics granularity. See [set_linear_velocity].
- void
set_angular_velocity( real angular_velocity )
Set the body angular velocity. Can be used sporadically, but** DONT SET THIS IN EVERY FRAME **, because physics may be running in another thread and definitely runs at a different granularity. Use [_integrate_forces] as your process loop if you want to have precise control of the body state.
-
real
get_angular_velocity( ) const
Return the body angular velocity. This changes by physics granularity. See [set_angular_velocity].
- void
set_max_contacts_reported( int amount )
Set the maximum contacts to report. Bodies can keep a log of the contacts with other bodies, this is enabled by setting the maximum amount of contacts reported to a number greater than 0.
-
int
get_max_contacts_reported( ) const
Return the maximum contacts that can be reported. See [set_max_contacts_reported].
- void
set_use_custom_integrator( bool enable )
Set to true if the body shall not do any internal force integration at all (like gravity or air friction). Only the [_integrate_forces] will be able to integrate them if overrided.
-
bool
is_using_custom_integrator( )
Return true if the body is not doing any built-in force integration.
- void
set_contact_monitor( bool enabled )
Enable contact monitoring. (the signals to notify when a body entered/exited collision).
-
bool
is_contact_monitor_enabled( ) const
Return wether contact monitoring is enabled.
- void
set_use_continuous_collision_detection( bool enable )
Enable continuos collision detection. This prevents very fast-moving bodies (such as bullets) to not go through objects.
-
bool
is_using_continuous_collision_detection( ) const
Return true if continuous collision detection is in use.
- void
set_axis_velocity( Vector2 axis_velocity )
Set an axis velocity. The velocity in the given vector axis will be set as the given vector length. (This is useful for jumping behavior).
Apply a positioned impulse (which will be affected by the body mass and shape).
- void
set_active( bool active )
Change the body state between sleeping/active states. As a note, static bodies can never be active.
-
bool
is_active( ) const
Return the body state. As a note, static bodies are never active.
- void
set_can_sleep( bool able_to_sleep )
Set the body ability to fall asleep when not moving. This saves an enormous amount of processor time when there are plenty of rigid bodies (non static) in a scene.
-
bool
is_able_to_sleep( ) const
Return true if the body has the ability to fall asleep when not moving. See [set_can_sleep].