Help creating a constant moving camera in GMS2

Discussion in 'Programming' started by Deltron_Akniv, Oct 9, 2018.

  1. Deltron_Akniv

    Deltron_Akniv Member

    Joined:
    Oct 9, 2018
    Posts:
    1
    I am a beginner at programming in gms and while I have down the basics of the camera and getting it to follow an instance I wanted to make a game in which the player would have to continually move up in order to not die. Behind this concept I wanted to make it so the camera is constantly moving up and maybe even moves faster if the player is closer to the top of the screen. I would greatly appreciate some input as to where to start figuring this out, I am not finding much online and am running out of steam in trying to figure this out on my own.

    The next thing I was going to try to do was to create an instance that the camera will follow that always will be moving up and just create an offset so that the instance will be at the top of the screen. Any thoughts on this idea would be appreciated as well.
    Thank You
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,032
    There are a number of camera tutorials on YouTube that you could look at (Shaun Spalding, Gloomy Toad, Friendly Cosmonaut). Instead of having the camera object seek the player, you just move the camera object itself at a speed (the say way you would an enemy or or something) or have the camera track another object which moves.

    If it were me, I would do it like this:
    • Create a camera
    • Create a target object
    • Have the camera follow the target object
    • Move the target object in the direction you want
    • Move the target object faster if the player gets close to it pseudo code:
    Code:
    
    if (dist_to_player < extra_speed_range) {
        extra_speed = 1 - (dist_to_player/speed_up_range)) * max_extra_speed
    }
    
    spd = movespeed + extra_speed
    //I'm doing this from memory and might have gotten it wrong. 
    //Basically if the player is close, it increases the speed by a percent of how close it is
    
    
    • Kill the player if they are outside of the camera - pseudo code:
    Code:
    
    with (player) {
        if (y > camera_y + camera_height) {
            instance_destroy();
        }
    }
    
    

    However, what you're describing is pretty close to a endless running. Often in an endless runner you move the world relative to the player. So that would be another option.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice