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

КОМЕНТАРІ • 105

  • @Baukereg
    @Baukereg 5 років тому +37

    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!

    • @paulomtts
      @paulomtts 3 роки тому +3

      I can't stress enough how much I hate those long tutorials filled with babbling and useless comments.

    • @masterjohn3126
      @masterjohn3126 Рік тому +1

      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

  • @puntastic1351
    @puntastic1351 16 днів тому

    5 years it's been and this is still a solid tutorial , great job mate

  • @leondecastro1807
    @leondecastro1807 5 років тому +9

    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!

  • @nyeponpon
    @nyeponpon 3 роки тому +4

    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!

    • @randokaratajev2617
      @randokaratajev2617 Рік тому +1

      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.

    • @nyeponpon
      @nyeponpon Рік тому

      @@randokaratajev2617 you have a fair point, I should've thought better before commenting this. I apologize.

  • @misterr3083
    @misterr3083 3 роки тому +12

    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.

  • @edp5623
    @edp5623 5 років тому +2

    I've watched many videos on cameras for gms2, this one helped me the most.

  • @TinyGamesLab
    @TinyGamesLab 5 років тому +4

    Great content, as always! Keep it up Matharoo!

  • @trex0n35
    @trex0n35 3 роки тому +1

    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 :))

  • @MacSacred
    @MacSacred 4 роки тому

    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.

  • @AngelloMaggio
    @AngelloMaggio Рік тому

    Love how direct your videos are, thank you so much for the help

  • @CoffeeAI201
    @CoffeeAI201 3 роки тому +5

    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

  • @cjd0308
    @cjd0308 3 роки тому +1

    Thank you so much for this tutorial. It was so helpful that I just signed up for your course!

  • @likwid-official
    @likwid-official 3 роки тому

    Thanks a ton for this tutorial! Very in-depth and helped me understand how all the of the code works!

  • @GuyHeroism
    @GuyHeroism 4 роки тому

    so awesome man!

  • @hector_dgz94
    @hector_dgz94 5 років тому +2

    your content is great, i wish you had more subs :D

  • @FoxyOfJungle
    @FoxyOfJungle 4 роки тому

    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

  • @TheAngryLibrarian
    @TheAngryLibrarian Рік тому

    Thank you so much! This was the first tutorial I found that covered both following and zooming (and actually worked in my GM).

  • @carlocgames2696
    @carlocgames2696 3 роки тому

    Simply the best!!!

  • @kevgmei
    @kevgmei 4 роки тому +1

    Thanks, dude! Quick and to the point. Definitely putting you in the credits of my game for helping me out.

  • @oakbyte4580
    @oakbyte4580 3 роки тому

    Amazing work, thank you so much, helped me alot!

  • @lilbigman5880
    @lilbigman5880 4 роки тому

    Awesome tutorial!

  • @ARamirez150
    @ARamirez150 2 роки тому +1

    Finally, another GML tutorial creator who's really good at explaining things! (Shaun Spalding and Heartbeast being the other two)

  • @bohdankulyk6672
    @bohdankulyk6672 Рік тому

    You are so kind to share this valuable information! Thank you very much!

  • @vosovoso5220
    @vosovoso5220 2 роки тому

    this is such a good tutorial!

  • @RylanVG
    @RylanVG 5 років тому

    Good video. You are clear and concise.

  • @chutney88
    @chutney88 3 роки тому

    Hi. Can this method of panning and zooming be combined with the 2.5d parallax camera? Thanks.

  • @betatester03
    @betatester03 4 роки тому +1

    Holy crap, man. This was a fantastic tutorial. I love your approach to presentation.

    • @GameMakerStation
      @GameMakerStation  4 роки тому

      Thank you :)

    • @joezuru3753
      @joezuru3753 Місяць тому

      @@GameMakerStation is there a way to make the camera pan ahead rather than behind

  • @wozatronics
    @wozatronics 3 роки тому

    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.

  • @wozatronics
    @wozatronics 3 роки тому

    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.

  • @powerpointdesigner7389
    @powerpointdesigner7389 3 роки тому

    How to zoom in out using Pinch events for mobile platform

  • @aerobetamax6022
    @aerobetamax6022 3 роки тому

    Genius!

  • @Damian_Stefann
    @Damian_Stefann 5 років тому

    I am not using gamemaker but these tutorials are perfect !!! i have some problems with differences but it´s perfect!

  • @Fioravante_
    @Fioravante_ 8 місяців тому

    THANK YOU MAN!

  • @m77mdsd3
    @m77mdsd3 4 роки тому +1

    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

  • @iMRDY99
    @iMRDY99 3 роки тому

    Thank you so much for the tutorial..

  • @nanashi3711
    @nanashi3711 4 роки тому +2

    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.

  • @sudechud
    @sudechud 5 років тому

    Very useful.Thanks

  • @herom123
    @herom123 4 роки тому

    Thankssss !!!!!!!

  • @johnroberts8088
    @johnroberts8088 5 років тому +2

    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?

    • @GameMakerStation
      @GameMakerStation  5 років тому +1

      You can modify this one to only pan and zoom, and not follow the player. Should work perfectly.

    • @johnroberts8088
      @johnroberts8088 5 років тому

      @@GameMakerStation Great thanks!!!! Keep up the amazing work!

    • @johnroberts8088
      @johnroberts8088 5 років тому

      @@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!!!

    • @GameMakerStation
      @GameMakerStation  5 років тому

      @@johnroberts8088 Yeah, you can store the camera's raw coordinates in your own variables, then interpolate (using lerp) the actual camera coordinates to them.

    • @johnroberts8088
      @johnroberts8088 5 років тому

      @@GameMakerStation Brilliant, thank you my friend, I will work on this. Congratulations on all your amazing content!

  • @Spoungebobsquarepan
    @Spoungebobsquarepan Рік тому

    Thanks a lot!!🙌

  • @mrnobody7600
    @mrnobody7600 Рік тому +1

    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.

  • @KrepperestlerStudio
    @KrepperestlerStudio 2 роки тому

    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.

  • @thirdworldrider6991
    @thirdworldrider6991 7 місяців тому

    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.

    • @BrendonReimer
      @BrendonReimer 5 місяців тому

      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;
      }

  • @nyeponpon
    @nyeponpon 3 роки тому

    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.

  • @lebedzecom
    @lebedzecom 3 роки тому

    Круто! А будет ли это работать м Android games?

  • @davidprestenberg5976
    @davidprestenberg5976 2 роки тому

    how can I change what object the cameras following and keep the camera in the exact same position it was following the first object?

    • @davidprestenberg5976
      @davidprestenberg5976 2 роки тому

      ooo i figured it out just storing cameras x and y in the destroy event so the new one has a starting point

  • @joezuru3753
    @joezuru3753 Місяць тому

    what if I want the camera to pan slightly AHEAD of the player rather than behind?

  • @pedroantonio743
    @pedroantonio743 5 років тому

    This tutorial is very useful, you could do a tutorial on how to do a screen shake efect?

    • @GameMakerStation
      @GameMakerStation  5 років тому

      Sure, I'll add that to my list. :)

    • @GameMakerStation
      @GameMakerStation  5 років тому

      Thanks for the suggestion. I've made a screenshake tutorial and uploaded it.

    • @pedroantonio743
      @pedroantonio743 5 років тому

      @@GameMakerStation thank you very much !!!!, you have helped me a lot.

  • @isaac7253
    @isaac7253 6 місяців тому

    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

  • @ariessuggs3819
    @ariessuggs3819 2 роки тому

    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

  • @NoahNCopeland
    @NoahNCopeland 4 роки тому

    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

    • @NoahNCopeland
      @NoahNCopeland 4 роки тому +2

      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.

  • @JustBrian.
    @JustBrian. Рік тому +2

    how to add a limit to zoom?

  • @stegeflott
    @stegeflott 4 роки тому +2

    How do I put a max zoom and a min zoom treshold??? in this code.....

    • @KowBasher
      @KowBasher 4 роки тому

      I second the question - I've been messing around with clamping the addW and addH values, but no luck so far.

    • @GameMakerStation
      @GameMakerStation  4 роки тому +2

      @@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!

    • @KowBasher
      @KowBasher 4 роки тому

      @@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!

    • @gnarsloggethesloth3085
      @gnarsloggethesloth3085 3 роки тому

      @@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

    • @mrnobody7600
      @mrnobody7600 Рік тому

      @@KowBasher man can you share your code?

  • @robinrozo
    @robinrozo 3 роки тому

    how i put limit to the zoom?

  • @rilysisumo9422
    @rilysisumo9422 4 роки тому

    when i zoom in it stretches everything horizontally.

    • @GameMakerStation
      @GameMakerStation  4 роки тому

      Hey, you can get help in our Discord server: discord.gg/TykHyqK

  • @leniwolf
    @leniwolf 2 роки тому

    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

  • @randokaratajev2617
    @randokaratajev2617 Рік тому

    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 ?

  • @AIO2011
    @AIO2011 5 років тому +4

    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

    • @GameMakerStation
      @GameMakerStation  5 років тому +2

      Good point!

    • @Riversofash
      @Riversofash 4 роки тому

      So do we just add instance_destroy(); after all the code in end step? I’m not sure I’m understanding

    • @AIO2011
      @AIO2011 4 роки тому

      @@Riversofash no, you could on the room change event add a camera destroy to avoid this memory leak

  • @MightyNO
    @MightyNO Рік тому

    6:56 For a second I thought my monitor was falling xDD

  • @dr.gadget9474
    @dr.gadget9474 2 роки тому

    👍👍👍👍👍👍👍👍

  • @oldbomb
    @oldbomb 3 роки тому +1

    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;
    }

    • @Boofener
      @Boofener Рік тому +1

      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

  • @arsray7285
    @arsray7285 Рік тому

    What accent is this?

  • @mattp8455
    @mattp8455 4 роки тому

    Your avoid is super awkward! However, good job I learned a lot!!

  • @dr.gadget9474
    @dr.gadget9474 2 роки тому

    СПАСИБО ЯНДЕКС ОЗВУЧКЕ ЧТО Я МОГУ СМОТРЕТЬ ЭТО НА РУССКОМ !!!!!

  • @officialshinky
    @officialshinky 5 років тому

    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 )

    • @GameMakerStation
      @GameMakerStation  5 років тому

      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.

    • @joshc7154
      @joshc7154 4 роки тому

      ​@@GameMakerStation Your accent is great, and very rare. Like George Agdgdgwngo. Thanks for the tutorial!!

  • @romkupar5647
    @romkupar5647 4 роки тому

    Omg,your accent is so weird)