KinematicBody2DMoveAndSlide Method |
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 and rotating platforms, or to make nodes push other nodes.
This method should be used in _PhysicsProcess(Single) (or in a method called by _PhysicsProcess(Single)), as it uses the physics step's delta value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
linear_velocity is the velocity vector in pixels per second. Unlike in MoveAndCollide(Vector2, Boolean, Boolean, Boolean), 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(Int32).
Namespace: Godot
public Vector2 MoveAndSlide( Vector2 linearVelocity, Vector2? upDirection = null, bool stopOnSlope = false, int maxSlides = 4, float floorMaxAngle = 0.785398f, bool infiniteInertia = true )
[Missing <param name="linearVelocity"/> documentation for "M:Godot.KinematicBody2D.MoveAndSlide(Godot.Vector2,System.Nullable{Godot.Vector2},System.Boolean,System.Int32,System.Single,System.Boolean)"]
[Missing <param name="stopOnSlope"/> documentation for "M:Godot.KinematicBody2D.MoveAndSlide(Godot.Vector2,System.Nullable{Godot.Vector2},System.Boolean,System.Int32,System.Single,System.Boolean)"]
[Missing <param name="maxSlides"/> documentation for "M:Godot.KinematicBody2D.MoveAndSlide(Godot.Vector2,System.Nullable{Godot.Vector2},System.Boolean,System.Int32,System.Single,System.Boolean)"]
[Missing <param name="floorMaxAngle"/> documentation for "M:Godot.KinematicBody2D.MoveAndSlide(Godot.Vector2,System.Nullable{Godot.Vector2},System.Boolean,System.Int32,System.Single,System.Boolean)"]
[Missing <param name="infiniteInertia"/> documentation for "M:Godot.KinematicBody2D.MoveAndSlide(Godot.Vector2,System.Nullable{Godot.Vector2},System.Boolean,System.Int32,System.Single,System.Boolean)"]
[Missing <returns> documentation for "M:Godot.KinematicBody2D.MoveAndSlide(Godot.Vector2,System.Nullable{Godot.Vector2},System.Boolean,System.Int32,System.Single,System.Boolean)"]