Function KinematicBody2D.moveAndSlide
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.
linear_velocity
is the velocity vector in pixels per second. Unlike in moveAndCollide
, you should not multiply it by delta
— the physics engine handles applying the velocity.
up_direction
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 stop_on_slope
is true
, body will not slide on slopes when you include gravity in linear_velocity
and the body is standing still.
If the body collides, it will change direction a maximum of max_slides
times before it stops.
floor_max_angle
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 infinite_inertia
is true
, body will be able to push RigidBody2D
nodes, but it won't also detect any collisions with them. If false
, it will interact with RigidBody2D
nodes like with StaticBody2D
.
Returns the linear_velocity
vector, rotated and/or scaled if a slide collision occurred. To get detailed information about collisions that occurred, use getSlideCollision
.
Vector2 moveAndSlide
(
const(Vector2) linear_velocity,
const(Vector2) up_direction = Vector2(0.00000F, , 0.00000F, , ) .this(0.00000F, 0.00000F),
const(bool) stop_on_slope = false,
const(long) max_slides = 4L,
const(double) floor_max_angle = 0.785398,
const(bool) infinite_inertia = true
) nothrow @nogc;