Godot - collisions -> do not understand..

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Alex1900

Hello! I need help!

Just try to going out of a heavy Unity, and replicate my simple game in Godot… So, trying to understand collisions.

What I have:
Hero (CharactedBody2D) with Sprite2D and CollisionShape2D
Enemy (RigidBody2D) with MeshInstance and CollisionShape2D
Bullet (Area2D) with Sprite2D and CollisionShape2D

All shapes are configured normally. So I need to take a collision from Hero and Bullet (depends what, to do diff things at Enemy side).

So, I linked Enemy:
func _on_body_entered(body):
print_debug(“FIRE!”)

So, from logical point of view it should works – Enemy should take collisions and depends on Body, I will use different logic…

But… This message ‘FIRE!’ happens only when Enemy laying (collide with) to ground!! Bullets, Hero, did not raise any collisions!

In Unity I just put OnCollisionEnter2D to Enemy script and get an all collisions with all needed objects, separate them by collision object name, tag etc… How to deal here?..

Thanks in advance!

:bust_in_silhouette: Reply From: godot_dev_

Sounds to me like you didn’t configure the collision_mask and collision_layer members of your collision bodies / areas properly. The default configuration is probably the reason why your enemy is detecting collisions with the floor. You should check out this forum post and this tutorial for help on masks and layers for collision detection.

Thanks for reply! I did a setup of masks & layers for every of my games’ nodes (like Player should interact with Ground/ Enemy, Enemy is with Player/Ground/Bullet, etc.), but result is absolutely the same ;(

Alex1900 | 2023-06-14 16:41

Could it be an issue with the way you connected your collisions handling function to the collision signals?

For example, Area2D has area_entered and body_entered signals, which are emitted when an area and body enters, repectively, so maybe you didn’t connect to the right signal (the bullet would be involved with area_entered while the enemy and player would be with body_entered, I beleive)

godot_dev_ | 2023-06-14 18:34