Enemy reset collision Issue

Godot Version

4.3, 2d

Question

I made a basic enemy where when you collide with it, the game resets but if it hits the ground it also resets, I found out that the collider is checking for all physics layers, so I tried to make another layer for the enemy to collide with the player but I cannot find it in the collision shapes, for now I am using RayCasts so enemies won’t hit the ground but now they just bounce of the player, Can someone help me please

What node type is your enemy using? If it’s a CharacterBody2D, you can use is_on_floor() to detect ground collisions. For player detection, I personally use an Area2D node with its own CollisionShape2D as a child of the enemy. Set the collision layer and mask so that this Area2D only detects the player, not the ground or other environment elements.

1 Like

Collision layers and masks can be found in the CollisionObject2D class, which is extended by CharacterBody2D, RigidBody2D or Area2D. You can’t find it in the CollisionShap2D.

And @mrdicerack gave a pretty good recommendation in regards to using Areas.

1 Like

Thanks! I’ve been using Areas to separate the player’s collision and hit logic. It helps keep things more organized and easier to manage for me.