Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions getting_started/first_3d_game/06.jump_and_squash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions getting_started/first_3d_game/07.killing_player.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions getting_started/first_3d_game/09.adding_animations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
}
Expand Down