0 votes

I have a project that generates a map based on a tilemap size and I want the player to be able to zoom in and out. The only problem is that if the player zooms out too much, they will surpass the bounds of the tilemap. I was wondering if there was a way to clamp the camera's maximum zoom. Thanks!

asked Jul 1 in Engine by wdylanbibb (14 points)

1 Answer

+1 vote

Sure, you can use clamp() and write your own zoom method, or do the clamps where you would otherwise be calling zoom changes.

extends Camera2D

const MIN_ZOOM = 0.5
const MAX_ZOOM = 1.5

func clamped_zoom(p_zoom : float) -> void:

    p_zoom = clamp(p_zoom, MIN_ZOOM, MAX_ZOOM)
    zoom = Vector2(p_zoom, p_zoom)

func _ready():


answered Jul 1 by avencherus (4,815 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.