From 2849dee2dc22b4d479ec5d5337e6d33eb265998d Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2024 04:11:34 +0200 Subject: [PATCH] Fix `MoveTowardsMouse` using the wrong coordinate system --- behaviours/move_towards_mouse.gd | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/behaviours/move_towards_mouse.gd b/behaviours/move_towards_mouse.gd index 8ab38fd..14552b7 100644 --- a/behaviours/move_towards_mouse.gd +++ b/behaviours/move_towards_mouse.gd @@ -8,8 +8,7 @@ signal captured @export_range(-500, 500, 1) var speed: float = 100.0 -@onready var viewport: Viewport = get_viewport() -@onready var camera: GameCamera = GameCamera.get_ancestor(self) +@onready var game := MainGame.get_ancestor(self) enum State { STILL, CAPTURED } @@ -18,9 +17,7 @@ var state: State = State.STILL func get_relative_mouse_position(): - var camera: Camera - var viewport_mouse_position: Vector2 = viewport.get_mouse_position() - var global_mouse_position: Vector2 = viewport_position + viewport_mouse_position + var global_mouse_position: Vector2 = game.camera.get_global_mouse_position() var relative_mouse_position: Vector2 = global_mouse_position - global_position return relative_mouse_position