Godot Version
Godot 4.2.2
Question
Help Programming General
As the title says, I need help in making the camera move slower based on the zoom.
Here is a video that describes my problem a little better than I did:
This is ALL the code used for the camera (36 lines)
extends Camera2D
var _target_zoom: float = 1.0
const MIN_ZOOM: float = 1.5
const MAX_ZOOM: float = 4
const ZOOM_INCREMENT: float = 0.2
const ZOOM_RATE: float = 8.0
func _ready() -> void: #At the start of the program, sets the camera to the min zoom
zoom_out()
func _physics_process(delta: float) -> void: #Zooms in with a smooth animation
zoom = lerp(zoom, _target_zoom * Vector2.ONE, ZOOM_RATE * delta)
set_physics_process(not is_equal_approx(zoom.x, _target_zoom))
func zoom_in() -> void: #Zooms in and makes sure that it doesnt go over the limit
_target_zoom = min(_target_zoom + ZOOM_INCREMENT, MAX_ZOOM)
set_physics_process(true)
func zoom_out() -> void: #Zooms out and makes sure that it doesnt go over the limit
_target_zoom = max(_target_zoom - ZOOM_INCREMENT, MIN_ZOOM)
set_physics_process(true)
func _unhandled_input(event: InputEvent) -> void: #Gets inputs that dont get handled by buttons
if event is InputEventMouseMotion:
if event.button_mask == MOUSE_BUTTON_MASK_LEFT:
if Input.is_action_pressed("drag"):
position -= event.relative * zoom #moves the camera in the opposite direction of the mouse to make the dragging effect
if event is InputEventMouseButton:
if event.is_pressed():
if event.button_index == MOUSE_BUTTON_WHEEL_UP: #If scroll up, zoom
zoom_in()
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: #If scroll down, dezoom
zoom_out()
Any help is appreciated, Thanks in advance.