From acda6511fcc8ea5fe01488c7e3a0b1f4a3683a6a Mon Sep 17 00:00:00 2001 From: toniuyt123 Date: Thu, 26 Oct 2023 17:18:26 +0300 Subject: [PATCH 1/2] Squash game bug on score tracking --- getting_started/first_3d_game/06.jump_and_squash.rst | 10 ++++++++-- getting_started/first_3d_game/07.killing_player.rst | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) 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 fc506847962..b1aef2e523b 100644 --- a/getting_started/first_3d_game/06.jump_and_squash.rst +++ b/getting_started/first_3d_game/06.jump_and_squash.rst @@ -251,7 +251,7 @@ With this code, if no collisions occurred on a given frame, the loop won't run. if collision.get_collider().is_in_group("mob"): var mob = collision.get_collider() # we check that we are hitting it from above. - if Vector3.UP.dot(collision.get_normal()) > 0.1: + if not mob.is_queued_for_deletion() and Vector3.UP.dot(collision.get_normal()) > 0.1: # If so, we squash it and bounce. mob.squash() target_velocity.y = bounce_impulse @@ -274,7 +274,7 @@ With this code, if no collisions occurred on a given frame, the loop won't run. if (collision.GetCollider() is Mob mob) { // We check that we are hitting it from above. - if (Vector3.Up.Dot(collision.GetNormal()) > 0.1f) + if (mob.IsQueuedForDeletion() && Vector3.Up.Dot(collision.GetNormal()) > 0.1f) { // If so, we squash it and bounce. mob.Squash(); @@ -300,6 +300,12 @@ information about where and how the collision occurred. For example, we use its The method ``is_in_group()`` is available on every :ref:`Node`. +Multiple Godot collisions can happend during the same frame including multiple collisions +with the same object. That is why we should prevent ourselves from emitting the squash events +multiple times by checking if the mob object is queued for deletion. This will work since +we will be deleting the mob once squashed. We do this with the ``is_queued_for_deletion`` +method. + To check that we are landing on the monster, we use the vector dot product: ``Vector3.UP.dot(collision.get_normal()) > 0.1``. The collision normal is a 3D vector that is perpendicular to the plane where the collision occurred. The dot product diff --git a/getting_started/first_3d_game/07.killing_player.rst b/getting_started/first_3d_game/07.killing_player.rst index db9447bdb05..cf9638bb40d 100644 --- a/getting_started/first_3d_game/07.killing_player.rst +++ b/getting_started/first_3d_game/07.killing_player.rst @@ -391,7 +391,7 @@ Finally, the longest script, ``Player.gd``: if collision.get_collider().is_in_group("mob"): var mob = collision.get_collider() # we check that we are hitting it from above. - if Vector3.UP.dot(collision.get_normal()) > 0.1: + if not mob.is_queued_for_deletion() and Vector3.UP.dot(collision.get_normal()) > 0.1: # If so, we squash it and bounce. mob.squash() target_velocity.y = bounce_impulse @@ -491,7 +491,7 @@ Finally, the longest script, ``Player.gd``: if (collision.GetCollider() is Mob mob) { // We check that we are hitting it from above. - if (Vector3.Up.Dot(collision.GetNormal()) > 0.1f) + if (mob.IsQueuedForDeletion() && Vector3.Up.Dot(collision.GetNormal()) > 0.1f) { // If so, we squash it and bounce. mob.Squash(); From c56310fb2203190c0af1ce81fdafb971f5de69b2 Mon Sep 17 00:00:00 2001 From: toniuyt123 Date: Thu, 26 Oct 2023 17:20:32 +0300 Subject: [PATCH 2/2] typo --- getting_started/first_3d_game/06.jump_and_squash.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 b1aef2e523b..1bfcdbc2c9c 100644 --- a/getting_started/first_3d_game/06.jump_and_squash.rst +++ b/getting_started/first_3d_game/06.jump_and_squash.rst @@ -300,9 +300,9 @@ information about where and how the collision occurred. For example, we use its The method ``is_in_group()`` is available on every :ref:`Node`. -Multiple Godot collisions can happend during the same frame including multiple collisions -with the same object. That is why we should prevent ourselves from emitting the squash events -multiple times by checking if the mob object is queued for deletion. This will work since +Multiple Godot collisions can happen during the same frame including multiple collisions +with the same object. That is why we should prevent ourselves from emitting the squash event +multiple times by checking if the mob node is queued for deletion. This will work since we will be deleting the mob once squashed. We do this with the ``is_queued_for_deletion`` method.