Question on Signals and collisions

Godot version 4.2.2

I’m very new to godot and I’m trying to wrap my head around how signals work with collisions. I have a signal set up to hit a method when an area2D object collides with a body.

func _on_battle_collision_body_entered(body):
	print("hit %s" % body)

This method is within the Walk state. And is used to check when the player collides with an enemy. I want to change to the battle state and begin fighting.
image

When I first made it I realized it was only colliding with the player so I tried switching around some layering in the collision mask but haven’t found any success.

I’ll post the images of each collision I’m working with and what each layer means for clarity.

1: Environment
2: player
3: battle (specifically for the players battleCollision)
4: enemy

Players main collision
image
I believe the player is set to its own layer and can only collide with the environment

Then the battleCollision
image
This is set to the battle layer and then can only interact with the enemy layer

And finally, the enemies collision
image
image
It is on the enemy layer and can collide with the battle layer.

What exactly am i missing?? When I run the game I never reach that log from the very first picture. Let me know if you need any other code snippets or screen shots! Thank you!

Okay I mocked up this layout just then and its working for me but just want to make sure I have this right:

image

I have the body_entered signal connected to the _on_battle_collision_body_entered function in the walk node.

I also set up the collision layers the same way you have it and I am getting the hit enemy console log.

Have I interpreted the node structure correctly or am I missing something? If I have got it right the only thing I can think of is maybe your signals aren’t connected properly? Make sure you’re not confusing body_entered and area_entered.

Sorry for the late reply but I ended up figuring it out. it was something very simple. I was trying to check for bodies in the area 2d when i should have been checking for areas!

1 Like

No worries glad you worked it out!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.