Trouble with 360 rotation in 3D space using mouse location

Godot Version

4.6

Question

I have a script here, which does properly register the mouse movement as something does happen, but not as I expected. I’m trying to test this out first rotating a cube, and then trying to instantiate a projectile going outwards at said point’s direction. This is the code I used to get this result, looking through a few tutorials, but my results were not quite the same.

func _process(delta: float) -> void:
    screen_point_to_ray()
		
func screen_point_to_ray():
	var target_plane_mouse = Plane(Vector3(0,1,0),player.position.y)
	
	#var space_state = player.get_world_3d.direct_space_state
	var mouse_pos = get_viewport().get_mouse_position()
	#var cam = get_tree().root.get_camera()
	var ray_origin = camera.project_ray_origin(mouse_pos)
	var ray_end = ray_origin * camera.project_ray_normal(mouse_pos) * 2000
	var cursor_pos_plane = target_plane_mouse.intersects_ray(ray_origin,ray_end)
	
	$"../CSGBox3D".look_at(cursor_pos_plane, Vector3.UP,0)

I have a video too demonstrating what the current rotation looks like using this code. The object in question is the white cube in the center of the player. It might be hard to tell, but the cube does not move to an angle relative to where the mouse is.

Check the Plane class reference. The second argument to Plane::intersect_ray() is not an endpoint, it’s a normalized direction vector. The ray length is assumed to be infinite.

I investigated these two lines, though I’m a bit confused still. I’m not sure what I should be changing if that makes sense, as I’m still not completely sure what each part should be doing differently?

Who wrote this code?

I followed two videos:

The method used in my code mostly came from the bottom linked video though. (one above this text.) I decided to look at the top one that used 3.4 after making this in case I missed anything and its closer to my use case. I did try to retry some of the code used there and a suggestion for 4.x in the comments, but I’m mostly just running into new problems.

Try:

var ray_normal = camera.project_ray_normal(mouse_pos)
var cursor_pos_plane = target_plane_mouse.intersects_ray(ray_origin, ray_normal)