Lethn That method doesn't give sensible data when the Ray isn't colliding with anything. My use case is that if the player looks into the sky, the bullets should still go to where the end of the ray is. I need to find the end point of the ray when it is NOT colliding with anything. get_collision_point() returns (0, 0, 0) if that is the case.
How do I get the global position of the end point of a moving RayCast3D?
- Edited
gowner Ah, in that case the common trick is to create an invisible wall for your ray to shoot at, you're still physically colliding with something but as far as the player is concerned they're shooting off into the distance and sorry, didn't properly read your OP and thought you were just asking about getting raycast data.
How about raycast.target_position - raycast.global_position
I think you meant raycast.target_position + raycast.global_position which makes sense at first because I was trying it but it was not working. The reason it does not work is that the raycast.target_position does not return the global position of the raycast target positions; it returns the local target position of the the scene that the raycast is in. So let’s say the player was to rotate, then the raycast would rotate with the player but the target position of the raycast would always stay the same since it is relative to the player scene. So when adding the raycast global position to the raycast target position we would be getting a vector that is pointing towards the original target position (in this case the original target position is where player is looking) and if the player was to rotate in the scene that we are working with we would still get the same target position as if the player never rotated. I hope this explains it well. Side note, if the object that we are working with does not rotate in the scene where you are getting global position then you would get the correct position that the ray is pointing at.
If we can get the global position of the raycast target position, then we don’t have to add anything since it’s already the global position. The whole point of the raycast.target_position + raycast.global_position was to get the global target position of the ray cast. So Darchenbauer was maybe trying to get the direction of the raycast by subtracting.