Skip to content

Instantly share code, notes, and snippets.

@NovemberDev
Created April 2, 2024 12:35
Show Gist options
  • Save NovemberDev/0498989b5fcb01461606279e7109b128 to your computer and use it in GitHub Desktop.
Save NovemberDev/0498989b5fcb01461606279e7109b128 to your computer and use it in GitHub Desktop.
Raycast from mouse position in 3D space in Godot
func raycast(camera: Camera3D):
var rayOrigin = camera.project_ray_origin(get_viewport().get_mouse_position())
var query = PhysicsRayQueryParameters3D.create(rayOrigin, rayOrigin + camera.project_ray_normal(get_viewport().get_mouse_position()) * 200);
return camera.get_world_3d().direct_space_state.intersect_ray(query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment