Godot Version
4.2.1
Question
I want to implement “building” into my game, i.e. letting the player place buildings in the game world. I want a building to be able to “snap” to another, such that it is easy for the player to place it at a good position.
The snapping should happen with respect to a ray. The already placed building has a certain connection point from which the ray extends into a certain direction. The player points roughly at the ray, and the building “ghost” should be snapped to the ray.
Specifically, the building should not necessarily be snapped directly to the connector on the other building, but just onto the ray, such that there may be some distance between the two. The space between them would then be filled by some sort of gangway.
Now, my question is about how to implement the snapping. I would like to do it in the way that the new building snaps to the point on the connector ray that is closest to the players cursor ray. So basically, the point on one ray that is closest to the other ray. I would be able to figure out the math for that myself, but I was wondering if I can skip this and if godot implements a function to compute the distance between two rays/straights in 3D?