This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+4 votes

(title)

in Engine by (45 points)

4 Answers

–1 vote

All you need is here: http://docs.godotengine.org/en/3.0/classes/class_camera2d.html
Check out the last option in the member variables.
You should be able to use that to change the zoom in script. I don't know how the code will look like bcoz I don't use Godot 3 .

by (420 points)
+6 votes

Hello! I'm from Russia. Sorry for my English.

I use this way:

1) Project > Project Settings > Input Map: create actions 'wheelup' and 'wheeldown'. 2) Add mouse buttons 'Wheel Up' and 'Wheel Down' for All Devices
3) And use this script:

func zoom():

        if Input.is_action_just_released(wheel_down'):
            $Camera2D.zoom.x += 0.25
            $Camera2D.zoom.y += 0.25
        if Input.is_action_just_released('wheel_up') and $Camera2D.zoom.x > 1 and $Camera2D.zoom.y > 1:
            $Camera2D.zoom.x -= 0.25
            $Camera2D.zoom.y -= 0.25

 func _physics_process(delta):

        zoom()
by (26 points)

hey, do you know how I would create a maximum zoom?

0 votes

Ulukanovich's answer doesn't work as it is in 4.0, so I converted it for 4.0:

extends Camera2D


func zoom():
    if Input.is_action_just_released('wheel_down'):
        set_zoom(get_zoom() - Vector2(0.25, 0.25))
    if Input.is_action_just_released('wheel_up'): #and get_zoom() > Vector2.ONE:
        set_zoom(get_zoom() + Vector2(0.25, 0.25))

func _physics_process(delta):
    zoom()

The differences are:

  • I commented out the limit
  • I reversed the zoom so its intuitive (wheel up doesnt zoom out!)
  • Removed $Camera2D since I used the above script on the camera itself. You could easily place back the $Camera2D
by (26 points)

I keep coming across people saying that X doesn't work for Godot 4 and providing a solution just for that and I made an account just to start saying thank you. It's helping me so much in learning the engine and starting off on 4.

I am happy to hear that my reply helped! Godot 4 is insanely powerful, and what prevents users from tapping into that power is not something lacking in the engine, but users cannot understand how to use something (lack of documentation)
Documentation has already heavily improved in the last few months, just like its stability (both of which are Godot's Achilles' heel)

I hope whatever feature you want for your game, you find good documentation, may that be text, video or even a full demo :)

0 votes
by (286 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.