0 votes

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 by Ole (78 points)

1 Answer

+1 vote
Best answer

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:
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 kidscancode (15,508 points)
selected May 5, 2019 by Ole

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 :)

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 :/

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.