From 99fc784dc3fa5aa834aefdee2d7fbbf28b43ada4 Mon Sep 17 00:00:00 2001 From: Nathan Lovato Date: Wed, 15 Jan 2020 14:25:41 +0100 Subject: [PATCH] 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 --- tutorials/physics/using_kinematic_body_2d.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tutorials/physics/using_kinematic_body_2d.rst b/tutorials/physics/using_kinematic_body_2d.rst index f4011859c..860debb23 100644 --- a/tutorials/physics/using_kinematic_body_2d.rst +++ b/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 --------