• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Help creating a constant moving camera in GMS2

D

Deltron_Akniv

Guest
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
 

samspade

Member
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.
 
Top