Nice logical approach. Getting a direction from an obj to a target obj is just a case of subtracting the target origin from the start point origin. So:
var tar_vec = ($RayCast.global_transform.origin - $Marker.global_transform.origin).normalized()
You can get the distance between them with:
var dist = $RayCast.global_transform.origin.distance_to($Marker.global_transform.origin)
If you want to get any point along the line:
var point_between = tar_vec * tar_dist * 0.5
0.5 gives you the point exactly halfway between the hand and the target.
You can't make a VR game without knowing this so I'll take a moment to explain why:
Imagine you had a starting position in 2d of say Vector2(1, 2)
(hand) and a target of Vector2(1, 4)
(ray cast interception point) then getting to the target vector from the hand means adding Vector2(0, 2)
- normalize this to a unit vector and you get Vector2(0, 1)
- it's above / on the positive y.
That's to say, Vector2(1, 4) - Vector2(1, 2) = Vector2(0, 2).normalized() = Vector2(0, 1)
. Then you can multiply this unit vector to scale it.
Hope that helps.
EDIT: This all assumes the ray cast is working and you have the target vector. If not you can get the direction vector of the ray and scale that unit vector. This can be got/set with $RayCast.cast_to
- in global space this is $RayCast.global_transform.origin + $RayCast.cast_to * scalar
Lazy option: You can save yourself the code and just go to "debug/visible collision shapes" at the top dropdown menu and Godot will show the ray when you run the game.