CollisionLayer and CollisionMask customization does not work

Godot Version

4.2 Mono

Question

I created a RigidBody2D node and through code I augment it with 3 nodes: sprite, shape, visibility on screen. I have specified the appropriate settings for everything, however, when I started to specify layer and mask settings, for some reason they didn’t work. See below
Godot_v4.2.1-stable_mono_win64_RssOUG2xHY


Second screenshot from the remote screen

if (projectileSettings.IsOnPlayer)
{
this.CollisionLayer = 4; // 4 - PlayerProjectile
this.CollisionMask = 3; // 3 - Enemy
}
else
{
this.CollisionLayer = 5; // 5 - EnemyProjectile
this.CollisionMask = 2; // 3 - Player
}

P.S. I can post the full script code if you need it

I might be totally off the mark here, but layers and masks are bit flags, so “3” means layers 1 and 2 are selected, not layer 3

1 Like

You may be right, but then I’m doubly ignorant of how to work with it, I posted a description of the layers above

I don’t know where to view the C# docs but in gdscript you can use set_collision_layer_value method.

Let me see if I can check

Well, it worked, I’m glad. However, the problem that I thought depended on the problem described above didn’t go away.

public override void _PhysicsProcess(double delta)
        {
            if (GetCollidingBodies().Count > 0 || !VisibleOnScreen.IsOnScreen())
			{
				QueueFree();
			}
        }

I thought that the get bodies method only returned the bodies specified in the mask, but it seems that’s not the case…

ContactMonitor = true;
MaxContactsReported = 1;

Those two lines fixed the second problem, I’m glad

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