KinematicBody2D

Inherits: PhysicsBody2D < CollisionObject2D < Node2D < CanvasItem < Node < Object

Category: Core

Brief Description

Kinematic body 2D node.

Member Functions

Variant get_collider ( ) const
Variant get_collider_metadata ( ) const
int get_collider_shape ( ) const
Vector2 get_collider_velocity ( ) const
float get_collision_margin ( ) const
Vector2 get_collision_normal ( ) const
Vector2 get_collision_pos ( ) const
Array get_move_and_slide_colliders ( ) const
Vector2 get_travel ( ) const
bool is_colliding ( ) const
bool is_move_and_slide_on_ceiling ( ) const
bool is_move_and_slide_on_floor ( ) const
bool is_move_and_slide_on_wall ( ) const
Vector2 move ( Vector2 rel_vec )
Vector2 move_and_slide ( Vector2 linear_velocity, Vector2 floor_normal=Vector2(0, 0), float slope_stop_min_velocity=5, int max_bounces=4 )
Vector2 move_to ( Vector2 position )
void revert_motion ( )
void set_collision_margin ( float pixels )
bool test_move ( Vector2 rel_vec )
bool test_move_from ( Matrix32 from, Vector2 rel_vec )

Description

Kinematic bodies are special types of bodies that are meant to be user-controlled. They are not affected by physics at all (to other types of bodies, such a character or a rigid body, these are the same as a static body). They have however, two main uses:

Simulated Motion: When these bodies are moved manually, either from code or from an AnimationPlayer (with process mode set to fixed), the physics will automatically compute an estimate of their linear and angular velocity. This makes them very useful for moving platforms or other AnimationPlayer-controlled objects (like a door, a bridge that opens, etc).

Kinematic Characters: KinematicBody2D also has an api for moving objects (the move method) while performing collision tests. This makes them really useful to implement characters that collide against a world, but that don’t require advanced physics.

Member Function Description

Return the body that collided with this one.

  • Variant get_collider_metadata ( ) const

Return the metadata of the shape that collided with this body. If there is no collision, it will return 0, so collisions must be checked first with is_colliding. Additionally, this metadata can not be set with Object.set_meta, it must be set with Physics2DServer.body_set_shape_metadata.

  • int get_collider_shape ( ) const

Return the shape index from the body that collided with this one. If there is no collision, this method will return 0, so collisions must be checked first with is_colliding.

  • Vector2 get_collider_velocity ( ) const

Return the velocity of the body that collided with this one.

  • float get_collision_margin ( ) const

Return the collision margin for this object.

  • Vector2 get_collision_normal ( ) const

Return the normal of the surface the body collided with. This is useful to implement sliding along a surface.

  • Vector2 get_collision_pos ( ) const

Return the point in space where the body is touching another. If there is no collision, this method will return (0,0), so collisions must be checked first with is_colliding.

  • Array get_move_and_slide_colliders ( ) const

Return the last movement done by the body.

  • bool is_colliding ( ) const

Return whether the body is colliding with another.

  • bool is_move_and_slide_on_ceiling ( ) const
  • bool is_move_and_slide_on_floor ( ) const
  • bool is_move_and_slide_on_wall ( ) const

Move the body in the given direction, stopping if there is an obstacle. The returned vector is how much movement was remaining before being stopped.

Move the body to the given position. This is not a teleport, and the body will stop if there is an obstacle. The returned vector is how much movement was remaining before being stopped.

  • void revert_motion ( )

Undo the last movement done by the body.

  • void set_collision_margin ( float pixels )

Set the collision margin for this object. A collision margin is an amount (in pixels) that all shapes will grow when computing collisions, to account for numerical imprecision.

Return true if there would be a collision if the body moved in the given direction.