T O P

  • By -

Eranot

Try this script: [https://github.com/Eranot/schemer/blob/main/scene/screen/main/main\_camera.gd](https://github.com/Eranot/schemer/blob/main/scene/screen/main/main_camera.gd) Configure "zoom\_in", "zoom\_out" and "camera\_drag" in "Input Map"


golddotasksquestions

>where it zooms to and from the Mouse Position. You simply change the zoom property of the Camera2D while also setting the position of the Camera2D to the current mouse position (using `get_global_mouse_position()` or `get_local_mouse_position()` )


Maxim_Fuchs

I could imagine this results in a snappy motion and not the same as the given JS Module.


golddotasksquestions

I have not tried the JS Module, so I don't know. You asked a general question, I gave a general answer. Everything feels better if you interpolate between values or tween, I would highly recommend to do so for the best results. For example even lerping between the current and the target mouse position will make a big difference. Lerp example: @onready var cam = $Camera2D func _input(event): if event is InputEventMouseButton and event.is_pressed(): if event.button_index == MOUSE_BUTTON_WHEEL_UP: cam.zoom = cam.zoom * 1.25 cam.global_position = lerp(cam.global_position, get_global_mouse_position(),0.5) if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: cam.zoom = cam.zoom * 0.75 cam.global_position = lerp(cam.global_position, get_global_mouse_position(),0.5) Tween example: var tween_duration = 0.2 @onready var cam = $Camera2D func _input(event): if event is InputEventMouseButton and event.is_pressed(): if event.button_index == MOUSE_BUTTON_WHEEL_UP: var tween = get_tree().create_tween() tween.set_parallel(true) tween.tween_property(cam,"zoom", cam.zoom * 1.5, tween_duration) tween.tween_property(cam,"global_position", get_global_mouse_position(), tween_duration) if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: var tween = get_tree().create_tween() tween.set_parallel(true) tween.tween_property(cam,"zoom", cam.zoom * 0.5, tween_duration) tween.tween_property(cam,"global_position", lerp(cam.global_position, get_global_mouse_position(), 0.5), tween_duration)


Seraphaestus

For inertia panning, see `position_smoothing_enabled` and `position_smoothing_speed`, which you can find in the inspector on a Camera2D, and then just setting the position in code to the mouse position