godotengine / godotengine/godot-docs
[enhancement][camera2D] simple zoom example in godot 4
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
**Your Godot version:**
Godot Engine v4.1.3.stable.arch_linux - https://godotengine.org
Vulkan API 1.3.242 - Forward+ - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce RTX 3060 Laptop GPU
**Issue description:**
camera2D : https://docs.godotengine.org/en/stable/classes/class_camera2d.html#class-camera2d-property-zoom
when you are new and you start in godot 4 the new concept of zoom will lose beginners/intermediate in mathematics
a small example can help many people understand this new version of zoom
```gdscript
var zoomTarget:float = 1
func _input(event):
if event.is_action("zoom in") or event.is_action("zoom out"):
# *(.2 * zoomTarget) to have the step between zoom in/out stable
# clamp alias min/max is to not flip the zoom and limit how many you can zoom
# get_axis to support mouse/key/joystick
self.zoomTarget = clamp(zoomTarget + Input.get_axis("zoom out","zoom in") * (.2 * zoomTarget), .42, 1)
pass
pass
func _process(delta):
_zoom(delta)
pass
func _zoom(delta):
if zoom.x != zoomTarget:
# lerp is to smooth the zoom and delta is to stabilize the lerp between fps
var zoomTmp = lerp(zoom.x, zoomTarget, 10 * delta)
zoom = Vector2(zoomTmp,zoomTmp)
pass
pass
```
**URL to the documentation page (if already existing):**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.