godotengine / godot

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

Cannot make `intersect_ray` work with viewport's `own_world` #62474

Open putgeminmouth opened 2 years ago

putgeminmouth commented 2 years ago

Godot version

v3.4.stable.mono.official [206ba70f4]

System information

macOS Catalina 10.15.7 (19h15), MacBook Air (Retina, 13-inch, 2020), 1.1 GHz Dual-Core Intel Core i3, 8 GB 3733 MHz LPDDR4X, Intel Iris Plus Graphics 1536 MB

Issue description

Hi,

I am trying to intersect a ray in a viewport that is not the root viewport but it never detects a collision.

My assumption is that if I create a viewport and set its world/own_world (in order to isolate its children from those of other viewports) that I should be able to cast a ray via a camera of that scene and detect collisions with children of that viewport.

I've done some sanity testing to ensure I can get a vanilla setup to work but as soon as I introduce an own_world to the viewport nothing works.

Am I missing / misunderstanding something?

image

Steps To Reproduce

Attached minimal repro project has a slowly spinning cylider and displays the result of a ray intersection using the mouse coordinates in an on-screen label each frame. Visible collision shapes is enabled for testing.

There is a boolean var demo_issue = false that toggles between showing the simple case that works (to show that the minimal repro code is generally valid) and the scenario I expect to work but does not.

Sanity check that works (demo_issue = false):

Example that does not work as expected (demo_issue = true):

Minimal reproduction project

62474.zip

Calinou commented 2 years ago

Can you reproduce this after switching the 3D physics engine to GodotPhysics in the Project Settings?

putgeminmouth commented 2 years ago

Can you reproduce this after switching the 3D physics engine to GodotPhysics in the Project Settings?

Yes, using any of GodotPhysics, Default, Bullet all produce identical behaviour.

rburing commented 2 years ago

In the minimal reproduction project modified to use Godot Physics, this continue statement in cull_segment of the BVH

https://github.com/godotengine/godot/blob/68b8dcdf50f02adf3105441b7b937a3b716d6ce9/core/math/bvh_cull.inc#L101-L103

is being triggered twice (i.e. all the time) in the own_world = true case (compared to just once when own_world = false).

Perhaps @lawnjelly can interpret what's going on there.

lawnjelly commented 2 years ago

is being triggered twice (i.e. all the time) in the own_world = true case (compared to just once when own_world = false).

Perhaps @lawnjelly can interpret what's going on there.

If the root node is NULL for all the trees, then it is likely there are no entries in the physics for the world that is being tested, there are essentially no objects to test against.