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) and MoveAndSlide(Godot.Vector2, Godot.Vector2?, float, int, float) 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.

Methods

    public Vector2 GetFloorVelocity()

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

    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?, float, int, float) call. Since the body can collide several times in a single call to MoveAndSlide(Godot.Vector2, Godot.Vector2?, float, int, float), you must specify the index of the collision in the range 0 to (GetSlideCount() - 1).

    public int GetSlideCount()

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

    public bool IsOnCeiling()

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

    public bool IsOnFloor()

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

    public bool IsOnWall()

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

    public KinematicCollision2D MoveAndCollide(Vector2 relVec)

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?), float slopeStopMinVelocity = 5f, int maxBounces = 4, float floorMaxAngle = 0.785398f)

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 a value in pixels per second. Unlike in for example MoveAndCollide(Godot.Vector2), you should not multiply it with delta — this is done by the method.

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 the body is standing on a slope and the horizontal speed (relative to the floor’s speed) goes below slopeStopMinVelocity, the body will stop completely. This prevents the body from sliding down slopes when you include gravity in linearVelocity. When set to lower values, the body will not be able to stand still on steep slopes.

If the body collides, it will change direction a maximum of maxBounces 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.

Returns the movement that remained when the body stopped. To get more detailed information about collisions that occurred, use GetSlideCollision(int).

    public void SetSafeMargin(float pixels)

Setter for Collision__safeMargin

    public bool TestMove(Transform2D from, Vector2 relVec)

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: