Hello, I'm trying to project my cursor's position onto a ground (I want to make a simple "point and click to move around" quest), I've found YT video that explains how to do it but it seems it is an outdated version and doesn't work in Godot 4.0 - few functions had different name and\or implementation.
I ended up with this, but it doesn't work as intended...
func ProjectCursor(cursor_pos):
var state = get_world_3d().direct_space_state
var camera = get_tree().root.get_camera_3d()
var rayO = camera.project_ray_origin(cursor_pos)
var rayend = rayO + camera.project_ray_normal(cursor_pos)*2000
var params = PhysicsRayQueryParameters3D.new()
params.from = rayO
params.to = rayend
params.exclude = [self]
params.collision_mask = 1
var rayArray = state.intersect_ray(params)
if rayArray.has("position"):
return rayArray["position"]
else:
return Vector3.ZERO