te1ny
February 7, 2024, 4:55pm
1
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
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
te1ny
February 7, 2024, 5:01pm
4
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.
te1ny
February 7, 2024, 5:02pm
6
Let me see if I can check
te1ny
February 7, 2024, 5:06pm
7
Well, it worked, I’m glad. However, the problem that I thought depended on the problem described above didn’t go away.
te1ny
February 7, 2024, 5:08pm
8
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…
te1ny
February 7, 2024, 5:12pm
9
ContactMonitor = true;
MaxContactsReported = 1;
Those two lines fixed the second problem, I’m glad
system
Closed
March 8, 2024, 5:13pm
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.