So I was recently creating a drag and move mechanic in my game and it was successful.
Then I just wanted to make the player look at the cursor with:
look_at(Vector3(pos.x, translation.y, pos.z), Vector3(0, 1, 0)
and it works...
However when I tested the game, the player suddenly doesn't go in the direction of the mouse; atleast some certain directions. When I removed the look_at() function, it definitely works... Can you help me please?
The function:
var space_state = get_world().direct_space_state
var mouse_position = get_viewport().get_mouse_position()
var cursor_pos = Vector3()
rayOrigin = camera.project_ray_origin(mouse_position)
rayEnd = rayOrigin + camera.project_ray_normal(mouse_position) * 20000
var intersection = space_state.intersect_ray(rayOrigin, rayEnd)
if not intersection.empty():
var pos = intersection.position
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
$Cursor/CursorMesh.visible = true
look_at(Vector3(pos.x, translation.y, pos.z), Vector3(0, 1, 0))
if Input.is_action_pressed("click"):
var point = Vector3(pos.x, translation.y, pos.z)
direction = point - transform.origin
motion = direction.normalized()
motion += transform.basis * direction
else:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
$Cursor/CursorMesh.visible = false`