Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | SASUPERNOVA |
I am trying to make a Camera2D object movable using the mouse, in a fashion similar to touchscreen scrolling, but I am getting an issue where the camera seems to “teleport” towards the upper left corner of the window before normal movement occurs. Is it possible to correct this behavior? So far, I am using the following code:
extends Camera2D
var isActive = false
var oldPos
func _ready():
pass
func _input(event):
isActive = Input.is_action_pressed("_lmb") #left mouse button
if Input.is_action_just_pressed("_lmb"):
oldPos = get_global_mouse_position()
if event is InputEventMouseMotion:
if isActive:
var newPos = oldPos - event.global_position
self.position = newPos