GUI in 3D demo, why manipulate event data?

Godot Version

4.2.2

Question

I’m currently going over the GUI in 3D demo as all the discussions I’ve read on the matter point to that, but I have some questions on why it’s seemingly necessary to manipulate the mouse event position, calculate the relative event distance, and track the duration since the last event.

I don’t understand why this isn’t just a simple raycast.

Don’t use the 3.x version of the code. Use the 4.x version here godot-demo-projects/viewport/gui_in_3d/gui_3d.gd at master · godotengine/godot-demo-projects · GitHub

It’s not manipulating the mouse input event because you need to convert the 3D coordinate system mouse event to the 2D coordinate system so the 2D part can react to it. In the 4.x version the raycast is done by the engine by enabling CollisionObject3D.input_ray_pickable and implementing the CollisionObject3D._input_event() function.

Oh yes, my mistake. I am using the 4.x version in my project, I mistakenly shared the wrong link to show the code.

Am I right in assuming event.velocity is the distance from the camera to the UI element being clicked? I ask because the issue I seem to be having is that I’m only able to click UI elements that are within the distance of the camera cone and I suspect the raycast isn’t being projected far enough.

I have Fixed Size enabled, I don’t know if that’s perhaps throwing it off.

No, InputEventMouseMotion.velocity is The mouse velocity in pixels per second. It has nothing to do with distance.

Fixed Size only affects the node visually and it does not modify the physics body. Raycasts only work with the physics system.