diff --git a/getting_started/first_3d_game/06.jump_and_squash.rst b/getting_started/first_3d_game/06.jump_and_squash.rst index 4f703b7acd8..b85663f7912 100644 --- a/getting_started/first_3d_game/06.jump_and_squash.rst +++ b/getting_started/first_3d_game/06.jump_and_squash.rst @@ -255,6 +255,8 @@ With this code, if no collisions occurred on a given frame, the loop won't run. # If so, we squash it and bounce. mob.squash() target_velocity.y = bounce_impulse + # Prevent further duplicate calls. + break .. code-tab:: csharp @@ -279,6 +281,8 @@ With this code, if no collisions occurred on a given frame, the loop won't run. // If so, we squash it and bounce. mob.Squash(); _targetVelocity.Y = BounceImpulse; + // Prevent further duplicate calls. + break; } } } @@ -309,6 +313,10 @@ With dot products, when the result is greater than ``0``, the two vectors are at an angle of fewer than 90 degrees. A value higher than ``0.1`` tells us that we are roughly above the monster. +After handling the squash and bounce logic, we terminate the loop early via the ``break`` statement +to prevent further duplicate calls to ``mob.squash()``, which may otherwise result in unintended bugs +such as counting the score multiple times for one kill. + We are calling one undefined function, ``mob.squash()``, so we have to add it to the Mob class. diff --git a/getting_started/first_3d_game/07.killing_player.rst b/getting_started/first_3d_game/07.killing_player.rst index db9447bdb05..1449394206a 100644 --- a/getting_started/first_3d_game/07.killing_player.rst +++ b/getting_started/first_3d_game/07.killing_player.rst @@ -395,6 +395,8 @@ Finally, the longest script, ``Player.gd``: # If so, we squash it and bounce. mob.squash() target_velocity.y = bounce_impulse + # Prevent further duplicate calls. + break # Moving the Character velocity = target_velocity @@ -496,6 +498,8 @@ Finally, the longest script, ``Player.gd``: // If so, we squash it and bounce. mob.Squash(); _targetVelocity.Y = BounceImpulse; + // Prevent further duplicate calls. + break; } } } diff --git a/getting_started/first_3d_game/09.adding_animations.rst b/getting_started/first_3d_game/09.adding_animations.rst index 154ab3ed168..42d118ad8b0 100644 --- a/getting_started/first_3d_game/09.adding_animations.rst +++ b/getting_started/first_3d_game/09.adding_animations.rst @@ -369,6 +369,8 @@ Here's the *Player* script. # If so, we squash it and bounce. mob.squash() target_velocity.y = bounce_impulse + # Prevent further duplicate calls. + break # Moving the Character velocity = target_velocity @@ -477,6 +479,8 @@ Here's the *Player* script. // If so, we squash it and bounce. mob.Squash(); _targetVelocity.Y = BounceImpulse; + // Prevent further duplicate calls. + break; } } }