The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Within a for loop, I:

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

However, the coordinates from getcollisionpoint 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))
in Engine by (15 points)

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*

1 Answer

+2 votes
Best answer

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.

by (713 points)
selected by

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.