Skip to content
Lukas Sägesser edited this page Jun 22, 2015 · 14 revisions

RigidBody2D

####Inherits: PhysicsBody2D ####Category: Core

Brief Description

Rigid body 2D node.

Member Functions

Signals

  • 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 )

Numeric Constants

  • 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.
  • CCD_MODE_DISABLED = 0
  • CCD_MODE_CAST_RAY = 1
  • CCD_MODE_CAST_SHAPE = 2

Description

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.

Member Function Description

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 ( float mass )

Set the body mass.

  • float get_mass ( ) const

Return the body mass.

  • void set_weight ( float 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.

  • float get_weight ( ) const

Return the body mass given standard earth-weight (gravity 9.8).

  • void set_friction ( float friction )

Set the body friction, from 0 (friction less) to 1 (full friction).

  • float get_friction ( ) const

Return the body friction.

  • void set_bounce ( float bounce )

Set the body bounciness, from 0 (no bounce) to 1 (bounce).

  • float 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 ( float 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.

  • float 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_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_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].

Clone this wiki locally