Browse Source

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
Nathan Lovato 5 years ago
parent
commit
99fc784dc3
1 changed files with 15 additions and 0 deletions
  1. 15 0
      tutorials/physics/using_kinematic_body_2d.rst

+ 15 - 0
tutorials/physics/using_kinematic_body_2d.rst

@@ -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
 --------