KinematicBody3D Move_and_slide vs. Move_and_collide ... Any logic in different input and output ???

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ole

According to documentation:

... takes a Vector3 "relative velocity"
... returns a KinematicCollision-object (possibly empty if no collision occured)

... takes a Vector3 "linear velocity"
... returns a Vector3 "linear velocity" (rotated/scaled if collision occured)


  1. What is the difference between “Linear velocity” and
    “Relative velocity”?

  2. What is the logic in returning different things, for functions that
    essentially does the same thing, with a slight twist?

  3. I would prefer if both functions returned same-type velocities, as
    they require for input, and then for me to query possible collisions
    manually … What am I missing?

  4. Why are Vector-maths melting my brain?

:bust_in_silhouette: Reply From: kidscancode

move_and_collide() is the basic movement method for kinematic bodies. It attempts to move the body along the given vector, stopping if it collides with another body. If a collision happens, it returns a collision object containing the details.

move_and_slide() was designed as a special case, because a common use case was to calculate a slide vector along the collision. However, because it slides, it’s possible for there to be more than one collision in a frame (think when you hit a corner between the floor and the wall. For this reason, it can’t return a collision, so you need to use the get_slide_collision() method to retrieve the details. Fun fact: move_and_slide() calls move_and_collide() internally to process the movement.

Both take a vector for the movement, but move_and_collide(), being the more basic method, is just the frame-based (ie multiplied by delta) movement vector. move_and_slide(), however, takes the pre-delta velocity (yes, this can be confusing).

Hopefully that clarifies it at least somewhat questions 1-3.

As for #4, what is melting your brain about vectors? Have you read this:
Vector math — Godot Engine (3.0) documentation in English ? I think it’s a pretty good overview of the topic specifically applied to its use in games.

Thanks for your answer

So, as to 1) … Relative vs. Linear is “Vector3*delta” vs. just “Vector3” … Both are “Relative to Frame-time”? … If so, I think the chosen nomenclature is somewhat confusing :slight_smile:

Just to clarify:
move_and_collide() should be fed a pre-multiplied velocity Vector3 (Vector3*delta).
move_and_slide() should be fed a raw velocity Vector3, and does the delta internally.

And yes, I have read the tutorial on vector-math, along with several other resources on the subject … Still I’m having troubles :confused:

PS: the most helpful info I got from you answer, is the fact that move_and_slide() calls move_and_collide() internally … that helps my understanding of what really is going on.

Ole | 2019-05-05 04:34