According to documentation:

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

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

Questions:

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?

asked May 5, 2019 in Engine

+1 vote

`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.

https://docs.godotengine.org/en/3.0/tutorials/math/vector_math.html ? I think it's a pretty good overview of the topic specifically applied to its use in games.

answered May 5, 2019 by (15,508 points)
selected May 5, 2019 by Ole

`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.
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.