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.