Godot Version
4.3
Question
I am making an RTS style camera, where the player can use WASD and move the cursor to the sides of the screen to move it. Eventually I’d like to add a middle click mouse anywhere in the viewport and move the screen that way.
Currently I have the WASD and the Cursor viewport edge movement down, but I’d like to prioritize the WASD over the Cursor position, since a WASD will likely always be intentional. How can I do this?
Currently my code is:
func _process(delta: float) -> void:
moveCameraWithKeys(delta)
moveCameraWithMouse(delta)
func moveCameraWithKeys(delta):
if Input.is_action_pressed("W"):
position.z -= CameraSpeed * delta
if Input.is_action_pressed("S"):
position.z += CameraSpeed * delta
if Input.is_action_pressed("D"):
position.x += CameraSpeed * delta
if Input.is_action_pressed("A"):
position.x -= CameraSpeed * delta
func moveCameraWithMouse(delta):
if (get_viewport().get_mouse_position().x >= get_viewport().get_visible_rect().size.x - MousePadding):
position.x += CameraSpeed * delta
if (get_viewport().get_mouse_position().x <= MousePadding):
position.x -= CameraSpeed * delta
if (get_viewport().get_mouse_position().y >= get_viewport().get_visible_rect().size.y - MousePadding):
position.z += CameraSpeed * delta
if (get_viewport().get_mouse_position().y <= MousePadding):
position.z -= CameraSpeed * delta