mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-03 05:48:42 +03:00
Explain why we store the return value from move_and_slide (#3001)
* Explain why we store the return value from KinematicBody2D.move_and_slide Close #2934 * Edit using_kinematic_body_2d, use direct voice over the passive voice
This commit is contained in:
committed by
Hugo Locurcio
parent
2b4319bc29
commit
99fc784dc3
@@ -138,6 +138,21 @@ Anything you do with ``move_and_slide()`` can also be done with ``move_and_colli
|
||||
but it might take a little more code. However, as we'll see in the examples below,
|
||||
there are cases where ``move_and_slide()`` doesn't provide the response you want.
|
||||
|
||||
In the example above, we assign the velocity that ``move_and_slide()`` returns
|
||||
back into the ``velocity`` variable. This is because when the character collides
|
||||
with the environment, the function recalculates the speed internally to reflect
|
||||
the slowdown.
|
||||
|
||||
For example, if your character fell on the floor, you don't want it to
|
||||
accumulate vertical speed due to the effect of gravity. Instead, you want its
|
||||
vertical speed to reset to zero.
|
||||
|
||||
``move_and_slide()`` may also recalculate the kinematic body's velocity several
|
||||
times in a loop as, to produce a smooth motion, it moves the character and
|
||||
collides up to five times by default. At the end of the process, the function
|
||||
returns the character's new velocity that we can store in our ``velocity``
|
||||
variable, and use on the next frame.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user