Skip to content

Squash the Creeps 3D Score Bug #7592

@J-John1

Description

@J-John1

Your Godot version:
4.0.2.stable

Issue description:
While making the "Squash The Creeps 3D" tutorial, I had an issue with the following piece of code, when trying to use it in the ScoreLabel to update the current score:

for index in range(get_slide_collision_count()):
	# We get one of the collisions with the player
	var collision = get_slide_collision(index)
	
	# If the collision is with ground
	if (collision.get_collider() == null):
		continue
	
	# If the collider is with a mob
	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 so, we squash it and bounce.
			mob.squash()
			target_velocity.y = bounce_impulse

When playing the game, each squashed creep increases the score by a random integer between 1-3 points each time. I believe this happens because the squashed signal is being emitted for each collision count. I tried putting "return" at the end of the "if collision.get_collider().is_in_group("mob"):" statement and this seemed to fix the problem. Due to the limitation of my programming experience, I believe it would be for the better if someone more knowledgeable could check the cause for this problem.

URL to the documentation page:
https://docs.godotengine.org/en/stable/getting_started/first_3d_game/06.jump_and_squash.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:getting startedIssues and PRs related to the Getting Started section of the documentationbug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions