Projectiles sometimes collide with walls and sometimes not

Godot Version

4.3

Question

I’m making a game similar to Bomberman. I have a level that has a tile map layer,
and that layer has three tiles - floor, unbreakable walls and breakable walls. I made an enemy that shoots. His projectiles should collide with walls and disappear, but sometimes projectiles go through walls.


I check if the projectile collides with walls by using OnBodyEntered signal of the attached Area2D and checking if atlas coordinate of projectile’s position doesn’t correspond to a floor tile:

public partial class Projectile : Node2D
{
	public Vector2 direction;
	public override void _Ready()
	{
		Area2D area2D = GetNode<Area2D>("Area2D");
		area2D.BodyEntered += body =>
		{
			if (body.Name == "Bomberman")
			{
				Bomberman bomberman = body as Bomberman;
				bomberman.Die();
				var sound = GetTree().GetRoot().GetNode<Node2D>("Level").GetNode<AudioStreamPlayer2D>("Shooter");
				sound.Play();
				QueueFree();
			}
			else if(body is TileMapLayer)
			{
				Walls walls = body as Walls;
				Vector2I mapPos= walls.LocalToMap(ToGlobal(Position));
				Vector2I atlas=  walls.GetCellAtlasCoords(mapPos);
				if (atlas != Walls.Floor)
				{
					var sound = GetTree().GetRoot().GetNode<Node2D>("Level").GetNode<AudioStreamPlayer2D>("Shooter");
					sound.Play();
					QueueFree();
				}
			}
		};
	}

	public override void _PhysicsProcess(double delta)
	{
		Position += direction;
	}
}

Help me to debug this or tell me if there’s a better way to handle this.

  1. Open your Projectile.
  2. Select your Area2D.
  3. Go to Inspector → CollisionObject2D → Collision
  4. Look at what Collision Mask is set.
  5. Open your walls that the projectile is going through.
  6. Go to Inspector → CollisionObject2D → Collision
  7. Make sure the Collision Layer is set to the same number as the projectile’s Mask.

This is most likely your problem.

too much concealment of bullets also has a speed

This sounds like a tunneling issue to me. Particularly with small, fast objects they can “tunnel” through other objects. This happens when the distance they move in a single physics step takes them from one side of an object to the other without landing on the object.

The Godot documentation actually has a section on it the physics troubleshooting section: Troubleshooting physics issues — Godot Engine (stable) documentation in English

That has a few suggestions on how to approach the problem, though (mainly for performance reasons) I would advise against changing the physics ticks per second unless you have a very good reason to. If the bullets are small and very fast, you might want to look into raycasting as a solution instead.