Kinematic body 2D node.
    public class KinematicBody2D : PhysicsBody2D

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 MoveAndCollide(Godot.Vector2, bool, bool, bool) and MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool) methods) while performing collision tests. This makes them really useful to implement characters that collide against a world, but that don’t require advanced physics.

Inheritance Chain

Constructors

    public KinematicBody2D()

Properties

    public float Collision__safeMargin { get; set; }

If the body is at least this close to another body, this body will consider them to be colliding.

    public bool Motion__syncToPhysics { get; set; }

If true, the body’s movement will be synchronized to the physics frame. This is useful when animating movement via AnimationPlayer, for example on moving platforms. Do not use together with MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool) or MoveAndCollide(Godot.Vector2, bool, bool, bool) functions.

Methods

    public Vector2 GetFloorVelocity()

Returns the velocity of the floor. Only updates when calling MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool).

    public float GetSafeMargin()

Getter for Collision__safeMargin

    public KinematicCollision2D GetSlideCollision(int slideIdx)

Returns a KinematicCollision2D, which contains information about a collision that occurred during the last MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool) call. Since the body can collide several times in a single call to MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool), you must specify the index of the collision in the range 0 to (GetSlideCount() - 1).

Example usage:

[codeblock]

for i in get_slide_count():

var collision = get_slide_collision(i)

print(“Collided with: “, collision.collider.name)

[/codeblock]

    public int GetSlideCount()

Returns the number of times the body collided and changed direction during the last call to MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool).

    public bool IsOnCeiling()

Returns true if the body is on the ceiling. Only updates when calling MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool).

    public bool IsOnFloor()

Returns true if the body is on the floor. Only updates when calling MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool).

    public bool IsOnWall()

Returns true if the body is on a wall. Only updates when calling MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool).

    public bool IsSyncToPhysicsEnabled()

Getter for Motion__syncToPhysics

    public KinematicCollision2D MoveAndCollide(Vector2 relVec, bool infiniteInertia = true, bool excludeRaycastShapes = true, bool testOnly = false)

Moves the body along the vector relVec. The body will stop if it collides. Returns a KinematicCollision2D, which contains information about the collision.

    public Vector2 MoveAndSlide(Vector2 linearVelocity, Vector2? floorNormal = default(Vector2?), bool stopOnSlope = false, int maxSlides = 4, float floorMaxAngle = 0.785398f, bool infiniteInertia = true)

Moves the body along a vector. If the body collides with another, it will slide along the other body rather than stop immediately. If the other body is a KinematicBody2D or RigidBody2D, it will also be affected by the motion of the other body. You can use this to make moving or rotating platforms, or to make nodes push other nodes.

linearVelocity is the velocity vector in pixels per second. Unlike in MoveAndCollide(Godot.Vector2, bool, bool, bool), you should not multiply it by delta — the physics engine handles applying the velocity.

floorNormal is the up direction, used to determine what is a wall and what is a floor or a ceiling. If set to the default value of Vector2(0, 0), everything is considered a wall. This is useful for topdown games.

If stopOnSlope is true, body will not slide on slopes when you include gravity in linearVelocity and the body is standing still.

If the body collides, it will change direction a maximum of maxSlides times before it stops.

floorMaxAngle is the maximum angle (in radians) where a slope is still considered a floor (or a ceiling), rather than a wall. The default value equals 45 degrees.

If infiniteInertia is true, body will be able to push RigidBody2D nodes, but it won’t also detect any collisions with them. When false, it will interact with RigidBody2D nodes like with StaticBody2D.

Returns the linearVelocity vector, rotated and/or scaled if a slide collision occurred. To get detailed information about collisions that occurred, use GetSlideCollision(int).

    public Vector2 MoveAndSlideWithSnap(Vector2 linearVelocity, Vector2 snap, Vector2? floorNormal = default(Vector2?), bool stopOnSlope = false, int maxSlides = 4, float floorMaxAngle = 0.785398f, bool infiniteInertia = true)

Moves the body while keeping it attached to slopes. Similar to MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool).

As long as the snap vector is in contact with the ground, the body will remain attached to the surface. This means you must disable snap in order to jump, for example. You can do this by setting snap to (0, 0) or by using MoveAndSlide(Godot.Vector2, Godot.Vector2?, bool, int, float, bool) instead.

    public void SetSafeMargin(float pixels)

Setter for Collision__safeMargin

    public void SetSyncToPhysics(bool enable)

Setter for Motion__syncToPhysics

    public bool TestMove(Transform2D from, Vector2 relVec, bool infiniteInertia = true)

Checks for collisions without moving the body. Virtually sets the node’s position, scale and rotation to that of the given Transform2D, then tries to move the body along the vector relVec. Returns true if a collision would occur.

Tags: