Raycast says it is not inside world when I force a raycase update?

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

Hi, I’m trying to perform a Raycast from the camera to the world using a RayCast object. This error comes up when I run ForceRaycastUpdate()

error

So, how do I make the RayCast work properly? Here’s my failed attempt (C#):

Vector3 rayOrigin = camera.ProjectRayOrigin(GetViewport().GetMousePosition()) 
    + camera.ProjectRayNormal(GetViewport().GetMousePosition());
Vector3 rayCastTo = camera.Transform.Xform(Vector3.Forward);
RayCast r = new RayCast();
r.Translation = rayOrigin;
r.SetCastTo(rayCastTo);
r.ForceRaycastUpdate();
Vector3 projPos = r.GetCollisionPoint();

If I remove the ForceRaycastUpdate() part, then it always returns (0, 0, 0)

I think you just missed adding it as a child of another node, before using it.

Dan Boorstein | 2018-07-24 03:32