Collision problem, with two character bodies

Godot Version

  • 4.2.1.stable -

Question

So the problem is with the collision layer and mask. I have a enemy, projectiles and player.

The problem lies with the projectiles passing through, but the player does collide and stop.

The layer and masks currently applied.
player - L(2) M (1, 3)

projectiles - L(4) M (3)

enemy - L(3) M (2, 4)

  • Example 1) Fail. - The problem

image

  • Example 2 ) Success. stopped by enemy

image

I think the bullets are checking for a different layer (mask: 3) than the player is on (layer 2).
Try setting the projectiles to mask 2 as well

HI, Sorry for the confusion, I could have worded this better I am trying to have the bullets hit the enemy not the player as I am aiming for a asteroids game.

You could use body.is_in_group or body.name to check what the bullet has touched.

	if body.is_in_group("tanks"):

or

	if body.name == ("player"):
1 Like

Thank you for the suggestion, But I am new to Godot and only trying to understand the layers and mask for collision’s currently.

I had a quick look at what you have suggested and I understand what your going for that would fix the problem/get round it I think.

But what I am trying to get & understand is why the projectile is not scanning the 3rd mask layer and interacting with the asteroid to improve my fundamental understanding of Godot, as no matter what I do the projectile is no behaving as it should from my understanding.

Just for more context on my little project.
More info on projectile)

More info on enemy)

More info on player)

Ok, so I have figured it out in conclusion I am stupid.

I WAS NOT USEING the physics system I think or at least velocity.

Explanation.

  1. The current projectile is using transform manipulation to move.

image

  1. The test projectile - That is moving across the screen via velocity.

image

Conclusion - layer and mask collision only work when using velocity or physics.

The test projectile moving via velocity and move_and_slide.
image

1 Like

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