Need clearance: does move_and_slide() already use delta?

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

“Linear velocity should not be multiplied by delta as this is done by the method” from the docs, but there are also plenty of examples that multiply by delta while using the method. So I’m hoping to clear up any confusion. Thanks!

:bust_in_silhouette: Reply From: kidscancode

The docs are correct. move_and_slide() internally multiplies the passed motion vector by delta.

What examples have you seen? Perhaps it’s move_and_collide(), which does not do this, or older 2.x demos that use move()?

Thanks for clarification. Well, one example from godotdocs-stable can be found on page 613 (pdf viewer page number) in section 9.1 “Physics Introduction”, it multiplies by delta before passing the vector into move and slide. This must be the example I’m remembering which left the doubt in my mind.

Anyway, thanks again :slight_smile:

Victorradley | 2018-12-31 06:36

I believe you’re talking about here:
Physics introduction — Godot Engine (latest) documentation in English

In the example, the gravity value is multiplied by delta, which is correct, because gravity is an acceleration vector. However, the velocity is passed to move_and_slide() without multiplying it.

kidscancode | 2018-12-31 06:45

That is the right example but it still makes no sense to me. You are multiplying delta on a part of the vector once, then multiplying again on the sum. Wouldn’t it make more sense to just let the function do it, as move and slide returns the unaltered vector (as if it were never multiplied by delta)

Victorradley | 2018-12-31 21:30

:bust_in_silhouette: Reply From: uzimonkey

Yes, it does. As always, use the source!

In Godot 3.0 you can see on the first line that it’s multiplying your linear velocity parameter by the fixed delta time. However, in Godot 3.1 (or the current master branch, presumably in Godot 3.1 when it’s released) it checks to see whether you called it from _process or _physics_process and multiplies the correct delta for you.

So these examples that show move_and_slide being called and multiplying by delta from GDScript are probably wrong. However, there is a similar function called move_and_collide that does not multiply by delta for you, you have to do it in GDScript.

Hey thanks! I’ll remember to check the source code next time. And it seems the function does return the unaltered linear velocity which I also wondered about.

Victorradley | 2018-12-31 21:33