![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | TheBlackHorse |
So, I am trying to raycast from the position of my mouse to a rigid body. The script seems to be ok, I have no errors, but the raycast does not hit anything. Any suggestions what the problem might be? I have attached a screenshot of my nodes.
func _physics_process(delta):
var rayOrigin = Vector3()
var rayEnd = Vector3()
var camera = get_tree().get_root().find_node("Camera", true, false)
if Input.is_action_just_pressed("leftclick"):
var space_state = get_world().direct_space_state
var mouse_position = get_viewport().get_mouse_position()
rayOrigin = camera.project_ray_origin(mouse_position)
rayEnd = rayOrigin + camera.project_ray_normal(mouse_position) * 2000000000
var intersection = space_state.intersect_ray(rayOrigin, rayEnd)
if not intersection.empty():
print(intersection.position)
h ttps://prnt.sc/1qoysgp
Please properly copy, paste, and format your code here. If a person has to reproduce your code, they probably won’t type it out by hand.
Ertain | 2021-08-29 00:36
Edited, thanks
TheBlackHorse | 2021-08-30 10:07