Raycast get_collision_point always returning same coordinates

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Unmanned

Within a for loop, I:

  • Create a new Transform() and give it a random origin point.
  • Set my RayCast to that transform using set_global_transform.
  • Print get_collision_point of the RayCast.

However, the coordinates from get_collision_point always equal the starting position of the RayCast (except for the y coordinate, which has changed to the floor where it is casting.)

Does anyone know why this could be happening?

var new_t = Transform(Vector3(1,0,0), Vector3(0,1,0), Vector3(0,0,1), Vector3(randi() % 100,50,randi() % 100))

It is difficult to reproduce your error without a test scene to debug.
That being said it seems that your Raycast has an origin but does not cast_to any particular vector.
I’ve found success in this method of using Raycasting:

$RayCast.translation = new_t.origin
$RayCast.cast_to = *SomeVector3*

RedSlimeSkirt | 2019-11-12 14:34

:bust_in_silhouette: Reply From: gmaps

Have you tried using

$Raycast.force_raycast_update( )

before printing?

When you move the raycast, it will acknowledge the movement in the next _physics_process call. If you want it immediately you have to force it with that function.

That’s exactly what I needed! I was unaware of the physics process call. I can’t believe I missed that function in the documentation.
Thank you very much.

Unmanned | 2019-11-12 16:04