• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Background following player

E

Edwin

Guest
Hello, people.

I want to sun background follow the player like Angry Sun in Super Mario Bros. 3.
So my player have the sort of friction (move speed simply adds for horizontal speed until it reaches maximum speed value). So here is the problem. The sun background doesn't know about friction and just move fast as possible. How to fix it?

Code:
Step Event:
Code:
// Player movement
if (keyboard_check(vk_right) && !keyboard_check(vk_left)) {
    if (hspd < max_speed) {
        hspd += move_speed;
    } else {
        hspd = max_speed;
    }
}

if (keyboard_check(vk_left) && !keyboard_check(vk_right)) {
    if (hspd > -max_speed) {
        hspd -= move_speed;
    } else {
        hspd = -max_speed;
    }
}

if ((!keyboard_check(vk_right) && !keyboard_check(vk_left)) || (keyboard_check(vk_right) && keyboard_check(vk_left))) {
    if (hspd > 0) { hspd -= move_speed; }
    else
    if (hspd < 0) { hspd += move_speed; }
}

// Following sun
background_x[0] = view_xview;
 
Top