Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | avencherus | |
Old Version | Published before Godot 3 was released. |
Anyone have any thoughts on the best way to pass mouse click coordinates accurately into a viewport of a 3D world, from clicking a viewportsprite that is rendering it?
I’m trying to click on 3D objects, but I’m heading down a path that is probably going to be way complicated than it probably needs to be.
The general easy way to get relative mouse coordinates is using a CollisionObject2D (like Area2D), maybe you can translate that value to the spatial viewport/camera and then I’m lost.
eons | 2016-10-28 12:57
What I ended up doing was just creating a function that forwarded the mouse position to the spatial node inside of the sub-viewport. From there I did a raycast of my own. The PhysicsServer version kept crashing, so I just used the node RayCast instead, and attached it to the camera.
As long as you don’t sub-scene it the spatial node, it will reference the viewport node’s dimensions.
Before I was doing some aspect ratio conversions, but after finding that it’s just become a couple lines of code. I’ll post the code as an answer.
avencherus | 2016-10-29 08:56