How to move object to mouse in 3D?

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

The question is pretty narrow but I can’t get the project to work from what I read in the official documentation.
I want to move a RigidBody to some point on the screen where the mouse is if it’s colliding with another PhysicBody(ground in my case), so I need a to cast a RayCast to the point where the cursor is and then move an object to the collision point.
I found this in official documentation

var from = camera.project_ray_origin(event.position)
var to = from + camera.project_ray_normal(event.position) * 1000

That sort of gives me the mouse position in the 3D world, but what do I do next?

:bust_in_silhouette: Reply From: Joel_127

Well, then you do the raycast :slight_smile:

var space_state = get_world().direct_space_state
var result = space_state.intersect_ray(from, to)