godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.95k stars 3.22k forks source link

CharacterBody2D move_and_slide() function inconsistency #6592

Open Exerionius opened 1 year ago

Exerionius commented 1 year ago

Your Godot version: v4.0.beta11.official [91713ced8]

Issue description: CharacterBody2D's move_and_slide() function inconsistency

URL to the documentation page (if already existing):

A note that velocity is multiplied by delta automatically in move_and_slide() was removed from the function's docs in 4.0:

Moves the body based on velocity. If the body collides with another, it will slide along the other body (by default only on floor) rather than stop immediately. If the other body is a CharacterBody2D 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.

Modifies velocity if a slide collision occurred. To get the latest collision call get_last_slide_collision, for detailed information about collisions that occurred, use get_slide_collision.

When the body touches a moving platform, the platform's velocity is automatically added to the body motion. If a collision occurs due to the platform's motion, it will always be first in the slide collisions.

The general behavior and available properties change according to the motion_mode.

Returns true if the body collided, otherwise, returns false.

but at the same time Using Character2D tutorial page still warns about it:

move_and_slide() automatically calculates frame-based movement using delta. Do not multiply your velocity vector by delta before passing it to move_and_slide().

Which one is true? Should it be multiplied by delta or was it changed in 4.0?

Exerionius commented 1 year ago

A side note:

Because of the same rename of KinematicBody2D into CharacterBody2D, the Kinematic character (2D) tutorial page became kinda confusing. It talks about kinematic bodies, but uses CharacterBody2D in the code examples because KinematicBody2D class no longer exists. Perhaps it makes sense to add some clarification to the paragraphs describing the differences between dynamic and kinematic characters by noting that dynamic characters are implemented using rigid bodies (already done), while kinematic characters are implemented using CharacterBody2D.

Exerionius commented 1 year ago

Is there any clarifications on whether we need to multiply by delta or not anymore in 4.x?

People are still asking this question to this day: https://www.reddit.com/r/godot/comments/13c8h7r/help_needed_with_characterbody3d_move_and_slide/

cbscribe commented 1 year ago

You literally don't even have a place to "multiply by delta". You set the velocity property in pixels/sec and call move_and_slide() with no arguments.

There will always be questions about this because people really don't understand units or the difference between distance and velocity.

At least less likely to lead to questions than it was before. The old text which was intended to clarify the difference between the two methods is now obsolete and should be removed.

Edit: I'll submit a PR removing that "Tip" today.

Exerionius commented 1 year ago

You literally don't even have a place to "multiply by delta".

You pretty much do. When setting a velocity property the first instinct is to multiply it by delta to make it framerate-independent, just out of a habit.

move_and_slide is the only place in the whole engine where you don't need delta multiplication to make it framerate-independent. People who haven't used Godot 3.x will not know this, especially the ones coming from other engines where delta multiplication is a must. Omitting this info from the docs means leaving these users blind to the fact that you should not go with your habit of delta multiplication when dealing with this one special case called move_and_slide, but should do it with everything else.

jerbrisebois commented 1 year ago

Also, the supplied example project from https://docs.godotengine.org/en/latest/tutorials/physics/using_character_body_2d.html ( https://github.com/godotengine/godot-docs-project-starters/releases/download/latest-4.x/character_body_2d_starter.zip ) has not been updated to 4.0 -i it still uses KinematicBody2d