Smooth Camera Tutorial + Pan/Zoom [GameMaker Studio 2]
Вставка
- Опубліковано 4 сер 2024
- This tutorial covers coding a smooth camera (using lerp) and panning+zooming the camera.
📃 Project Download: www.dropbox.com/s/6npeyqa27jj...
🐤 Follow me on Twitter: / itsmatharoo
📚 Enroll in my best course: www.udemy.com/gamemakerstudio2
💗 Join our Discord server: / discord
This is how I like tutorial videos: quick and to the point. I was struggling with camera zooming but your video is very helpful. Cheers mate!
I can't stress enough how much I hate those long tutorials filled with babbling and useless comments.
quick and to the point? theres only 2 lines of code anybody actually needs to know in the entire video yet its over 7 minutes
5 years it's been and this is still a solid tutorial , great job mate
You know, I was having a bad day because I couldn't implement my camera properly until I saw this video.
Good thing I subscribed to you back then, you are a god send sir GameMakerStation!
I'm really impressed by how fast you go to the video's point. Usually, GMS tutorials in YT are made by someone who do not plan how to do the video in first place, there is no script and they get lost quickly or make useless long comments.
Thanks a lot, keep it up!
What if I told you I'm really impressed with the other comments that don't mock other creators while praising this channel?
I understand you wanted to praise this creator but you could have done it in a more civil way.
How can one be that ignorant to rant others who are educating you for free? It's not like they have millions of viewers/subs. Most peak at 100k max and that's pretty much nothing compared to todays youtube standards.
@@randokaratajev2617 you have a fair point, I should've thought better before commenting this. I apologize.
Such an incredible tutorial, so short but packed with an amazing amount of clear and useful information! You are so good at making tutorials. There is an art to clarity and simplicity and you have nailed it! Really really appreciate it.
I've watched many videos on cameras for gms2, this one helped me the most.
Great content, as always! Keep it up Matharoo!
Thank you!
I just gotta say, I love that your out here making quality content. This is such an upgrade to the camera I had before, I can't thank you enough :))
Outstanding tutorial, thanks alot.
I like the animations you did to frame the precise parts you're talking about, it allows the tutorial to be more dynamic and get straight to the point. It also helped structuring the code in my mind. I'm amazed at the quality of this video.
Love how direct your videos are, thank you so much for the help
For anyone experiencing a jitter when the camera gets close to the target, replace “/“ with “div” when dividing by 2
This seems to be an issue with larger resolutions. I’ve noticed it in sprites with a lot of detail. Switching from “/“ to “div” cleans up the division and really smooths the camera out
Thanks so much for this
Thank you so much for this tutorial. It was so helpful that I just signed up for your course!
Thanks a ton for this tutorial! Very in-depth and helped me understand how all the of the code works!
so awesome man!
your content is great, i wish you had more subs :D
Thank you so much! You helped me a lot! I spent all my day trying to do it but wasn't too good like this! I subscribed. :D
Thank you so much! This was the first tutorial I found that covered both following and zooming (and actually worked in my GM).
Simply the best!!!
Thanks, dude! Quick and to the point. Definitely putting you in the credits of my game for helping me out.
Amazing work, thank you so much, helped me alot!
Awesome tutorial!
Finally, another GML tutorial creator who's really good at explaining things! (Shaun Spalding and Heartbeast being the other two)
also FriendlyCosmonaut
You are so kind to share this valuable information! Thank you very much!
this is such a good tutorial!
Good video. You are clear and concise.
Hi. Can this method of panning and zooming be combined with the 2.5d parallax camera? Thanks.
Holy crap, man. This was a fantastic tutorial. I love your approach to presentation.
Thank you :)
@@GameMakerStation is there a way to make the camera pan ahead rather than behind
Greetings, thanks for the Tut, I'm only a lowly beginner at coding lol. But very easy to follow and re create. Thanks for your hard work. Its appreciated.
Fantastic Matharoo, well over my head, but awesome to use in my current project. Thanks for you time and effort in making these videos.
Because of my lack of knowledge in using gamemaker, I cant get the camera to work across multiple rooms :-( Any help would be appreciated.
I've attached a draw event to the camera, that draw a sprite for the background, it slowly rotates, it works on the great on the first room, but then it disappears on the 2nd room.
Thanks.
Paul.
How to zoom in out using Pinch events for mobile platform
Genius!
I am not using gamemaker but these tutorials are perfect !!! i have some problems with differences but it´s perfect!
Great, what engine do you use?
THANK YOU MAN!
can you make a 2 players camera tutorial and when the 2 players are near to each other the camera will be 1 and if they arenot they will be 2 cameras one for first player and one to the second
Thank you so much for the tutorial..
This is one of my favorite GameMaker tutorials! Great job!
Note that zooming outside the size of the room will cause the camera to move in a way that the camera will cause the room to appear in the bottom right.
One of the easiest ways to fix this is by commenting out the clamp functions and then the camera will center the room just fine.
Very useful.Thanks
Thank you communist banana
Thankssss !!!!!!!
Great tutorial, any chance on making one where you drag/pan/zoom like you would on google maps? So not follow a player but smooth click/drag/pan with just the mouse?
You can modify this one to only pan and zoom, and not follow the player. Should work perfectly.
@@GameMakerStation Great thanks!!!! Keep up the amazing work!
@@GameMakerStation Sorry one last question, do you think it is possible to pan and add easing one you let go of the mouse? You know what I mean? So you drag and pan then on release it still moves a bit easing down to stop. Thanks!!!
@@johnroberts8088 Yeah, you can store the camera's raw coordinates in your own variables, then interpolate (using lerp) the actual camera coordinates to them.
@@GameMakerStation Brilliant, thank you my friend, I will work on this. Congratulations on all your amazing content!
Thanks a lot!!🙌
How can I make it so the camera won't exceed the room's width and height? I don't want the players to see the black parts.
5:13 I did the exactly same thing. But game is subtracting _movex and _movey variables from camx and camy for each step. So camera position reaches to -ten thousands in a second.
hi my friends, love the camera, adapted it to my space 2d game. I am wondering which value would I have to manipulate to get a smooth zoom with the mouse wheel instead of like a stepping or increment zoom. Like if I shove the mouse wheel forward, it'll keep zooming until it reached the desired value then stop. I tried making a zoom factor based on the mouse wheel, but cannot get it to go that way.
I basically want to add a max zoom out level and a max zoom in level. I dont think it can be done with the current code how the mouse wheel is used to zoom.
A max cameX/Y position changes based on where the player is, so setting a max for that wont work.
Instead of using a mouse zoom, I made it so clicking shift and alt would alter the variables zoomTargetW and zoomTargetH
then did this in the step
if (camW < zoomTargetW) && (camH < zoomTargetH)
{
addW = (zoomTargetW - camW) * 0.2;
addH = (zoomTargetH - camH) * 0.2;
camW += addW;
camH += addH;
// Position
camX -= addW / 2;
camY -= addH / 2;
}
if (camW > zoomTargetW) && (camH > zoomTargetH)
{
addW = (camW - zoomTargetW) * 0.2;
addH = (camH - zoomTargetH) * 0.2;
camW -= addW;
camH -= addH;
// Position
camX += addW / 2;
camY += addH / 2;
}
Oh, also, I have a question: is it possible to make a "perimeter" where the cam can move? I don't wanna players to move the camera outside the room- it gets a ugly visual bug when it happens.
Use clamp() as it is shown in this video.
Круто! А будет ли это работать м Android games?
how can I change what object the cameras following and keep the camera in the exact same position it was following the first object?
ooo i figured it out just storing cameras x and y in the destroy event so the new one has a starting point
what if I want the camera to pan slightly AHEAD of the player rather than behind?
This tutorial is very useful, you could do a tutorial on how to do a screen shake efect?
Sure, I'll add that to my list. :)
Thanks for the suggestion. I've made a screenshake tutorial and uploaded it.
@@GameMakerStation thank you very much !!!!, you have helped me a lot.
Really great except that there's a weird little jitter when the player stops moving and the camera slows to a halt, tried using div instead of /, but that didn't fix my problem
Anyone figure out how to restore original zoom level? is there a way to original level before changing it so I can make it go back? I is dum lol
How would one tie this to a variable, like "Zoom," so that all you would have to do is increase or decrease Zoom and it will do the work...?
In otherwise, how to divorce this from mousewheel
Figured it out. It's quite simple. Posting for others:
all you need is this in step:
camera_set_view_size(camera,CamW*Zoom,CamH*Zoom)
just make sure that CamW and CamH are set in the create event and never touched again.
how to add a limit to zoom?
need this!
How do I put a max zoom and a min zoom treshold??? in this code.....
I second the question - I've been messing around with clamping the addW and addH values, but no luck so far.
@@KowBasher Hi! You can apply clamping to the camW/camH after adding the addW/addH to them.
Example:
camW = clamp(camW + addW, minimumWidth, maximumWidth);
However, this won't affect the "camX -= addW / 2" part, which means that the camera will still be offset. To fix that, you can simply wrap the camera offset part inside a conditional block, which would check if the camW/H have changed at all (which means that you have to store the original camW/H before changing them, in separate variables, and then do a != comparison for the offset block).
Hope this helps!
@@GameMakerStation Thanks! I had it almost working but your code smoothed out the camera zoom when it hit the min/max height. (it would twitch)
I found that by clamping the max value by room_width and height did the trick for my game as the map is a single grid.
Thank you so much for the reply and help! Great videos and editing!
@@GameMakerStation I'm having a problem with twitching when the camera hits the min/max zoom? This comment thread seems to address this but I'm not sure if I'm doing it right, because with the info here it still twitches
@@KowBasher man can you share your code?
how i put limit to the zoom?
Use clamp()
@@GameMakerStation thank you
when i zoom in it stretches everything horizontally.
Hey, you can get help in our Discord server: discord.gg/TykHyqK
not working for me, going insane. no idea what i'm doing wrong but when i import this code into my project, it's not working
tried it. Works fine but I think you forgot one of the key features about zoom in games: They are limited.
Your code lets you zoom out more than the room size itself. How would one limit this to room_width or height ?
The tutorial is very good and helpful, but, in no point of the tutorial you explained that the created camera has to be deleted, specially when dealing with room changes. This could lead to some serious memory leaks. So anyone watching this tutorial, beware with that ;P
Good point!
So do we just add instance_destroy(); after all the code in end step? I’m not sure I’m understanding
@@Riversofash no, you could on the room change event add a camera destroy to avoid this memory leak
6:56 For a second I thought my monitor was falling xDD
👍👍👍👍👍👍👍👍
Very nice tutorial as always, but I would like to add if you want to return to your starting resolution one time, it is better to use multiplying instead of adding for zooming, like this:
//Zooming
var factor = .1;
var wheel = (1 +(factor *mouse_wheel_down()) ) /(1 +(factor *mouse_wheel_up()) );
if wheel != 1 and zoom *wheel > zoom_min and zoom *wheel < zoom_max{
zoom *= wheel;
var corr_w = w *(1 -wheel) /2
var corr_h = h *(1 -wheel) /2
w = other.view_width /zoom;
h = other.view_height /zoom;
//correction position center
x -= corr_w;
y -= corr_h;
}
where are you defining zoom? and view_width/view_height? im trying to add it to my dumb project but it just doesnt wanna work with what he has in the video
What accent is this?
Your avoid is super awkward! However, good job I learned a lot!!
СПАСИБО ЯНДЕКС ОЗВУЧКЕ ЧТО Я МОГУ СМОТРЕТЬ ЭТО НА РУССКОМ !!!!!
I liked the video, you put a lot of work in this i see! Don't let people hate on you because of your accent( just subscribe to pewdiepie and they'll love you )
Thanks! By now I'm used to people not liking my accent. I just try to do my best and to improve at the same time.
@@GameMakerStation Your accent is great, and very rare. Like George Agdgdgwngo. Thanks for the tutorial!!
Omg,your accent is so weird)