In my first person game I have a RayCast3D node to detect what the player is looking at. To test it, I set a ball mesh to the raycast collisition point every frame. But, it seems to be going to random values!? How can I fix this?
func _physics_process(delta: float) → void: #set global posisiton
if rayCast.is_colliding():
var intersection_point = rayCast.get_collision_point()
Global.crossHairPOS = intersection_point
crossHair.position = Global.crossHairPOS
else:
Global.crossHairPOS = Vector3(0, -3.452, 0)
crossHair.position = Global.crossHairPOS
Please place multiline code inbetween three grave accents ``` to format the code properly.
Also, why is crossHairPOS a global variable? Is there another script that needs it and can’t reference this one directly?
About your issue:
I don’t understand the point of setting the position of what I assume is the ball mesh to Vector3(0, -3,452, 0) specifally.
If the ball mesh and raycast are children of the player, the reason for the “random” positions are probably that you are setting the ball meshes local position to the raycasts output global position. See the docs about Raycast3D.get_collision_point:
Returns the collision point at which the ray intersects the closest object, in the global coordinate system