0 votes

I'm wondering if you can make camera zooming without adding in a new input. It probably involves using the _input function, but I'm not sure.

Godot version 3.2.3
in Engine by (56 points)

What do you mean adding in a new input? If you're talking about adding something new to the InputMap, no, you don't have to, but using it make it a lot easier

Can you explain in what way you will use this? so we can understand more

I'm using this in a [3D] game that's like Kerbal Space Program

Yeah, I mean by adding something to the input map.

Yeah you don't need to use the input map at all, you can just check the event properties directly. But I don't recommend that

1 Answer

+2 votes
Best answer
func _input(event):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_WHEEL_UP:
            fov += 1 #Camera
            #zoom += 1 #Camera2D
        elif event.button_index == BUTTON_WHEEL_DOWN:
            fov -= 1 #Camera
            #zoom -= 1 #Camera2D

For the 3D camera node in some cases it may be better to get the distance between the camera and target the lerp the Camera's transform in steps

by (4,604 points)
selected by

Sorry, but I can't understand the 3D camera stuff you said here (I don't know what lerping is, & I also don't know how to get the camera's transform in steps), can you explain via code?

var step = 2
var camera_position = camera.global_transform.origin
var target_position = target.get_global_transform().origin
var zoom = camera_position.move_toward(target_position, step)
camera.global_transform.origin = zoom
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.
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 webmaster@godotengine.org with your username.