godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.15k stars 21.19k forks source link

StaticBody3D collisions does not scan layers of RigidBody3D #89259

Open Pshy0 opened 8 months ago

Pshy0 commented 8 months ago

Tested versions

System information

Godot v4.3.dev4 - Ubuntu 23.10 23.10 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1650 () - Intel(R) Core(TM) i5-10300H CPU @ 2.50GHz (8 Threads)

Issue description

In a 3D scene with a static body (ground) on collision layer 1 scanning layer 1, and rigid body on layer 1 not scanning any layer, the rigid body passes through the ground.

The scene setup: image image When run: image When collision masks are swapped (rigid body scans, static body does no longer scan): image

I would have expected, because the rigid body is in layer 1, and ground scans that layer, that the rigid body be stopped by it.

This happens with different collision shapes, and order of nodes does not influence the result.

Either this is a bug, or it is missing from documentations that static bodies never scan collision layers of other objects. On one hand, it could make sense that because they dont move, static bodies would not get to scan other bodies. But on the other hand, when I asked on discord, someone said that it was working for them, and also this observation makes the ragdoll tutorial form the doc not work because it is setup the way I setup my scene, so that looks like a bug more than a doc problem, so I open an issue in this repo.

Steps to reproduce

Just run the MRP. Maybe you'll need to enable visible collision shapes. image

You may change collision masks to see that the other way around, when the rigid body scans layers and not the static body, collisions work as expected.

Minimal reproduction project (MRP)

collision-scan.zip

AThousandShips commented 8 months ago

This sounds expected, the rigid body scans and doesn't find anything in the other body, it is what's doing the checks as the static body is static, as you can see it works correctly when you swap it

This is documented id say, see here

Pshy0 commented 8 months ago

This is documented id say, see here

This is where it should be documented, but I don't see mention of different behaviors between static and rigid bodies at this location.

AThousandShips commented 8 months ago

It does say that the body doesn't scan, the rigid body is the one that's moving, so I'd say it's expected that if it doesn't hit anything it doesn't get affected, right?

I don't know where to clarify this, if it is needed

Pshy0 commented 8 months ago

It does say that the body doesn't scan,

I don't read this... can you quote the sentence from the doc that says that? When I search "scan" all I find is this:

This describes what layers the body will scan for collisions. If an object isn't in one of the mask layers, the body will ignore it. By default, all bodies scan layer 1.

Pshy0 commented 8 months ago

In the ragdoll tutorial, the static bodies are set to scan, while the ragdoll bones are set not to. The observed behavior is incompatible with the instructions from this tutorial.

AThousandShips commented 8 months ago

On the property?

Pshy0 commented 8 months ago

On the property?

It says this:

Note: Object A can detect a contact with object B only if object B is in any of the layers that object A scans.

I don't think it's enough to guess that static bodies behave in a different way than rigid bodies. I would expect either A or B to be able to detect the other and cause a collision. We could setup a similar scene with the same settings/properties, but with both objects being rigidbodies, and it would behave differently. I think it should be explicitly said that static bodies does not use this property... if this really is expected.

AThousandShips commented 8 months ago

You asked for where it said the body doesn't scan, and I answered that :)

Hiiamwilliam commented 8 months ago

How collision masks and layers interact in order to detect a collision changed from Godot 3 to 4. The way you expected,

rigid body is in layer 1, and ground scans that layer, that the rigid body be stopped by it

is how Godot 3 works. This is not the case in Godot 4, as far as I know.

You can see a difference in the Note below collision mask/layer (Collision Object documentation):

Therefore, the behavior shown is working correctly. I suppose this is why you were answered on Discord that "it is working".

this observation makes the ragdoll tutorial form the doc not work because it is setup the way I setup my scene, so that looks like a bug more than a doc problem

It seems to be a doc problem. The tutorial on Godot 4 is mostly copy-pasted from Godot 3 just with updated class names. The image at the bottom of the page even shows the Godot 3 name "Kinematic". Make sure to open an issue in the docs repository.