I am trying to make a camera that you can drag around to pan around an area. In my current implementation, the movement is very choppy and not very accurate or responsive.
The _input(event) is used to start and stop the drag, and the _process(delta) is supposed to keep track of the mouse movement on a frame-by-frame basis.
Any help is appreciated.
extends Node2D
var LastMouseCoords = get_global_mouse_position()
var CurrentMouseCoords = LastMouseCoords
var dragState = false
onready var cam = get_node("Camera2D")
func _process(delta):
CurrentMouseCoords = get_global_mouse_position()
if dragState:
var diff = LastMouseCoords - CurrentMouseCoords
cam.translate(diff)
LastMouseCoords = CurrentMouseCoords
func _input(event):
if event is InputEventMouseButton and event.button_index == BUTTON_RIGHT:
if not dragState:
dragState = true
else:
dragState = false