How to make camera zooming?

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

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.

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

exuin | 2021-04-18 21:56

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

Mrpaolosarino | 2021-04-19 02:03

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

slightly_seasoned | 2021-04-19 20:07

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

slightly_seasoned | 2021-04-19 20:08

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

exuin | 2021-04-19 20:17

:bust_in_silhouette: Reply From: Wakatta
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

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?

slightly_seasoned | 2021-04-19 20:21

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

Wakatta | 2021-04-19 20:52