Panning and Zooming system in Godot in 2 min +Source Code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi there in today's tutorial we're diving into creating a panning and zooming system in gdau so let's get started first let's take a quick look at our basic scene setup we got some houses some trees and other objects here now let's create a new scene with a camera 2D as the bass node attach a script to it and name it whatever you'd like now let's take a look at our code and I'll explain how it works first off we have these variables here that control various aspects of our camera like the Zoom speed sets the speed of zooming Min zoom and Max Zoom Define the minimum and maximum Zoom levels and drag sensitivity sets the sensitivity of dragging here we are using the input function this function is a built-in function in GD script it gets called whenever an input event occurs in the C input events can include Mouse clicks Mouse movements keyboard presses Etc this section checks if the middle Mouse button is pressed while moving the mouse if true it adjusts the camera position based on the relative movement of the mouse the camera moves in the opposite direction of the mouse movement scaled by the drag sensitivity and divided by the zoom speed and the current zoom level you can use any kind of input event for this like is action pressed Etc here the code checks if there's a mouse wheel event again you can use any other input event for this in in this case if the wheel is scrolled up it zooms in by adding to the current zoom level if the wheel is scrolled down it zooms out by subtracting from the current zoom level we use a vector 2 here because the camera zoom has both X and Y Zoom values finally this line of code ensures that the zoom level remains within the defined minimum and maximum Zoom levels it uses the clamp function to restrict the zoom level between Min zoom and Max Zoom again use a vector to here is to provide both X and Y Zoom limits and there we have it and it works like charm you can download the project files from the description and enjoy if you have any questions let me know down in the comments till then goodbye
Info
Channel: Wabsa Studios
Views: 58
Rating: undefined out of 5
Keywords: godot, wabsastudio
Id: O5LByFmc0jk
Channel Id: undefined
Length: 2min 21sec (141 seconds)
Published: Sun May 12 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.