Setting camera zoom to weapon range ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wildboar

So I am able to calculate weapons range and draw it on screen, now I wonder how can I calculate that distance into camera zoom ?

I wish to with melee weapon equipped set camera to zoom Vector2(1, 1), else zoom out enough for player to see full attack range of the weapon…

Let me know if you need an image to clarify what I mean.

Got it working with following formula, tested on current weapons only however, not sure if it will stop working properly when I add longer range weapons.

var zoom = clamp(get_weapon().attack_range / 500, 1.5, 5)
camera.zoom = Vector2(zoom, zoom)

wildboar | 2021-02-20 10:50