Legacy GM Background following player

Edwin

Member
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