• 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 Camera lerping issues

N

Nexusrex

Guest
Hello there everyone.
I've been dealing with my platformer's stages as a multiple screen style, similar to what Megaman did with it's stages. So I based my camera over Shaun Spalding's 'Sliding Camera' tutorial to lock the camera in specific positions.
When it comes to vertical lerping -to switch from screen to screen-, it works perfectly. But once I attempt to do it horizontally, it focuses on the player object for a few frames like if it had no limits and then lerps to the position.
A gif for better explanation:


As for the code I use for the camera:

Create event:
Code:
global.shake = 0;
global.selectedscroll = 0;
insideboss = false;
if room != rm_hatsu1
{
nlx = room_width;
nly = room_height;
nsx = 0;
nsy = 0;
}
else
{
nlx = 2560;
nly = 720;
nsx = 0;
nsy = 360;
}

if room != rm_hatsu1
{
limitx = room_width;
limity = room_height;
startx = 0;
starty = 0;
}
else
{
limitx = 2560;
limity = 720;
startx = 0;
starty = 360;
}

Step event:
Code:
///Follow player and screenshake
if room != room51
{
    if (!insideboss)
    {
        if instance_exists(obj_player)
        {
            view_xview[0] = -(view_wview[0]/2) + obj_player.x;
            view_yview[0] = -(view_hview[0]/2) + obj_player.y;

            view_xview[0] = clamp(view_xview[0],startx,limitx-view_wview[0]);
            view_yview[0] = clamp(view_yview[0],starty,limity-view_hview[0]);
        }
        if instance_exists(obj_phatsu)
        {
            view_xview[0] = -(view_wview[0]/2) + obj_phatsu.x;
            view_yview[0] = -(view_hview[0]/2) + obj_phatsu.y;

            view_xview[0] = clamp(view_xview[0],startx,limitx-view_wview[0]);
            view_yview[0] = clamp(view_yview[0],starty,limity-view_hview[0]);
        }
    }
    if instance_exists(obj_pswim)
    {
        view_xview[0] = -(view_wview/2) + obj_pswim.x;
        view_yview[0] = -(view_hview/2) + obj_pswim.y;

        view_xview[0] = clamp(view_xview,0,room_width-view_wview);
        view_yview[0] = clamp(view_yview,0,room_height-view_hview);
    }
}

if (insideboss)
{
    switch(room)
    {
        case rm_training:
            if view_xview[0] != 2560
            {
            view_xview[0] = lerp(view_xview[0],2560,0.2);
            }
            if view_yview[0] != 720
            {
            view_yview[0] = lerp(view_yview[0],720,0.2);
            }
            nlx = room_width;
            nly = room_height;
            nsx = 2560;
            nsy = 720;
        break;
        case rm_lvfirst:
            if view_xview[0] != 1904
            {
            view_xview[0] = lerp(view_xview[0],0,0.2);
            }
            if view_yview[0] != 727
            {
            view_yview[0] = lerp(view_yview[0],0,0.2);
            }
        break;
    }
}
//Screenshake
view_xview[0] += random_range(-global.shake,global.shake);
view_yview[0] += random_range(-global.shake,global.shake);
global.shake *= 0.9;
//Make sure it lerps
if startx != nsx
{
    startx = lerp(startx,nsx,0.2);
}
if starty != nsy
{
    starty = lerp(starty,nsy,0.2);
}
if limitx != nlx
{
    limitx = lerp(limitx,nlx,0.2);
}
if limity != nly
{
    limity = lerp(limity,nly,0.2);
}

Room start event:
Code:
if instance_exists(obj_player)
{
x = (obj_player.x div view_wview[0]) * view_wview[0]
y = (obj_player.y div view_hview[0]) * view_hview[0]
}

To change the limit and start variables, I use some objects that I place across the room where the player collides with to run that code:
Code:
obj_cam.nlx = other.limitx;
obj_cam.nly = other.limity;
obj_cam.nsx = other.startx;
obj_cam.nsy = other.starty;

Thanks in advance!
 
Top