• 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!

GMS 2 Player Elevation

I

inkBot

Guest
Ok, so I've been trying to solve this for a few days on my own, but I think I may have written myself into a corner.
My game is supposed to control like a beat em up, and so far I have made good progress. You can walk around, and you can jump (the jumping isn't perfect yet, since you can become offset currently, but it at least works).

Now I'm trying to implement elevation into this mix so that you can jump up on higher grounds. I had an idea of how to do it, namely having an elevationValue variable that changes depending on what ground tile you're standing on, and then the value is added to the positioning of the character. But... I'm having trouble actually getting it to work.

Create event:
Code:
//movespd = 3;
combotimer = 0;

playerFlip = image_xscale;

hsp = 0;
vsp = 0;
zsp = 0;
jumpspeed = 13;
movespeed = 6;
elevation_value = 0;
onElevation = false;

state = p1_states.normal;
 
IsAttacking = false;
AttackType = 0;
MaxHP = 100;
CurrentHP = MaxHP;
I**** = false;
 
OnGround = true;
GroundY = y;
 
image_speed = 1;

det_input= " ";
last_input= " ";
this_input= " ";
motion= " ";
Movement script:
Code:
sc_p1_getinputs();

h_move = control_left + control_right;
v_move = control_up + control_down;

x += hsp;
if (hsp != 0) xor (vsp != 0 and OnGround == true)
    {
        sprite_index = spr_playerwalk;
    }
    else sprite_index = spr_playeridle;

if (h_move != 0)
    {
        image_xscale = sign(h_move);
    }

GroundY += vsp;

if (OnGround == false)
    {
        if (h_move != 0 and v_move != 0)
            {
                hsp = h_move * (movespeed*0.6);
                vsp = v_move * (movespeed*0.6);
            }
            else
            {
                hsp = h_move * (movespeed*0.8);
                vsp = v_move * (movespeed*0.8);
            }
       
        zsp += global.grav
        y += vsp + zsp;
        if (y >= GroundY)
            {
                OnGround = true;
                zsp = 0;
            }
    }
    else
    {
        y += vsp;
        if (control_jump == 1)
        {
            OnGround = false;
            zsp = jumpspeed * -control_jump;
        }
        if (h_move != 0 and v_move != 0)
            {
                hsp = h_move * (movespeed*0.8);
                vsp = v_move * (movespeed*0.8);
            }
            else
            {
                hsp = h_move * movespeed;
                vsp = v_move * movespeed;
            }
       
    }
   
   
if (point_in_rectangle(x,GroundY,
                    ob_floor_elevation40.x,
                    ob_floor_elevation40.y,
                    ob_floor_elevation40.x+ob_floor_elevation40.sprite_width,
                    ob_floor_elevation40.y+ob_floor_elevation40.sprite_height))
    {
        onElevation = true;
        elevation_value = -40;
    }
    else
    {
        onElevation = false;

    }

if (onElevation == true)
    if (GroundY != GroundY + elevation_value)
        {
            GroundY = GroundY + elevation_value;
        }
    else if (elevation_value != 0)
    {
        GroundY = GroundY + (elevation_value*-1);
        elevation_value = 0;
    }
The last "if (onElevation == true)" statement I recently added. It doesn't work either.
I'm currently in a continuous loop of adding and removing pieces of code to see if they work, so that's why there may be redundancies in the code above.
 
Top