The area2D has the same collision shape as the projectiles collision shape
I am running code in C# on the body entered signal: _area2D.Connect("body_entered", new Callable(this, MethodName.OnBodyEntered));
The following is the collision mask and layer of Area2D
This code is what is triggered when a body is detected.
public void OnBodyEntered(Node2D body) {
GD.Print(body);
QueueFree();
}
The issue I am having is that the OnBodyEntered function is only run if the projectile hits a PhysicsBody2D and not when hitting a TileMap in almost every case.
The only case when GD.Print(body) prints a Tilemap is when the projectile is up against a tilemap and I move the player to touch the projectile and the player and tilemap will both be printed.
This is very strange behaviour and I have looked through everything that could seemingly cause this and it doesnt make an sense to me.
Here is a video of what is happening with the prints as well.
I understand this and correct me if I’m wrong but should that not mean it is triggered when it hits the wall still? and if for some reason it was always inside the tilemap it should have been triggered right at the beginning when it is initialised but it isnt so I don’t see how that would affect it.
What about your Projectile’s collision mask and layer? Seems like it’s stopping against the wall, maybe the character body’s collision shape is the same size or larger than the area2d’s. Could the Area2D be the root instead? Why use a CharacterBody2D for the projectile?
The projectile has the same collision layer and mask as the Area2D. I’m using a characterbody2d so I can do move_and_slide calculations on it.
I have tried making the collision shape on the area2d slightly bigger than the projectile itself incase the projectile is blocking other things from hitting it but that has not made a difference.
I don’t understand what you mean. Could you explain it differently?
Are you saying even when the projectile is not touching the wall it’s still triggering a enter signal?
I thought that might be the case but if it were it would be triggering the signal once at least and it doesnt trigger at all. I moved the character that spawns the projectile to the wall so that the projectile would spawn in the wall and in that case it does trigger the signal, just not when moving into it from outside
Area don’t make signals when things already inside only when something from outside enter. Anyway could be better if your bullets use olny one collider insted two if possible.
I understand that it only triggers when something enters the collider but I’m saying that that isn’t why it doesn’t trigger. If it wasn’t triggering when hitting the wall because it is already colliding with the tilemap then either:
it would trigger when it is first created, which is isn’t
it wouldn’t trigger if it spawned inside the wall, which if I have the projectile spawn inside the wall it does trigger as expected.
This tells me that there is some other issue causing this.
I need to have 2 collisionShapes because I need it to be a CharacterBody2D so I can manipulate it’s velocity and I need it to have an Area2D to detect colliding bodies which both need their own collisionShapes.
I have found a solution. Turning off the characterbodys collision mask seeing terrain allowed it to move into the wall enough to get triggered. Thank you for everyone for your help.