Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No collisions between player and rocks in SpaceRocks #29 #29

Open
JohnLudlow opened this issue Jul 26, 2024 · 0 comments
Open

No collisions between player and rocks in SpaceRocks #29 #29

JohnLudlow opened this issue Jul 26, 2024 · 0 comments

Comments

@JohnLudlow
Copy link

(reraised from PacktPublishing/Godot-Game-Engine-Projects#29)

I'm following the SpaceRocks project but I'm having an issue with detecting Player / Rock collisions. This is almost certainly something I'm doing wrong, I'd just appreciate a pointer as to what that might be.

I've connected a signal to a C# (yes I'm using C#) method on Player.on_body_entered:

image

	public void OnBodyEntered(Node body)
	{
		Debug.WriteLine("collided with something!");
		if (body.IsInGroup("rocks") && body is Rock rock)
		{
			rock.Explode();
			Lives--;
			Explode();
		}
	}

The problem is this signal's method is never invoked. I've put a breakpoint at the start of this method and it's just never hit when the player ship and rock meet. I also never see the debug output.

My code for my current attempt

JohnLudlow / GodotTraining / SpackeRocks

Things I've already checked

  • The player has contact monitor enabled:
    image

  • The player has a collision shape:
    image

  • The rocks have a collision shape
    image

Thanks for the quick response and that's a good thing to check. If I remember correctly, the project in the book doesn't ask you to do anything specific with the collision layers.

  • Everything (rocks and player) is on collision layer 1, mask 1

image

  • Collisions between rocks and bullets (which are Area2D's) work fine (which also suggests the collision shape is correct)

  • I've downloaded the sample project and compared property-by-property and can't see what I'm missing

  • I've made a much simpler project to test collisions between RigidBody2D objects: JohnLudlow / GodotTraining / 2dColisionTester and collisions do trigger the signal.

Conclusion

So I'm pretty sure this is something obvious I'm missing but I can't see what so I'd really appreciate a pointer or two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant