Legacy GM Slope (Diagonal) Platforms?

S

Sokyogoku

Guest
Hi, I would like my game to have diagonal platforms. The problem is that I have little idea on how to add the code in. so far my character can go down these slopes but when going up them they seem to not have collisions.

I'm also kind of slightly above the beginner level but no more. The collision code I have from old Shaun Spalding's platformer tutorials (because I can't make my own and I couldn't find newer ones that include slopes).
Code:
    ///colliding with stuff
   
    //horizontal collisions
    var hcollide;
    hcollide = instance_place(x+hspd, y, obj_par_collision);
   
    if (hcollide !=noone) {
        if (hcollide.collision ==1) {
            yplus = 0;
            //the number in brackets for abs indicated how many pixels high a slope can be
            while (place_meeting(x+hspd, y-yplus, obj_par_collision) && yplus<= abs(1*hspd)) {
                yplus += 1;
            }
            if (place_meeting(x+hspd, y-yplus, obj_par_collision)) {
                while (!place_meeting(x+sign(hspd), y, obj_par_collision)) {
                    x += sign(hspd);
                }
                hspd = 0;
            } else {
                y -= yplus;
            }
        }
    }
    //move horizontally
    x += hspd;
   
    //vertical collisions
    var vcollide;
    vcollide = instance_place(x, y+vspd, obj_par_collision);
   
    if (vcollide != noone) {
        if (vcollide.collision == 1) {
            while (!place_meeting(x, y+sign(vspd), obj_par_collision)) {
                y += sign(vspd);
            }
            vspd = 0;
            mground = 1;
        } //platform collisions
        if ((vcollide.collision ==2) && sign(vspd) == 1) {
            if (!place_meeting(x, y, obj_par_collision)) {
                while (!place_meeting(x, y+sign(vspd), obj_par_collision)) {
                    y+=1;
                }
                vspd = 0;
                mground = 1;
            }
            if (place_meeting(x, y, obj_par_collision) || (obj_player.dkey)) {
                with obj_player {
                scr_gravity();
                mground = 0;
                }
            }
        }
    } else {
        mground = 0;
    }
    //move vertically
    y += vspd;
To explain, variable collision 1 are solids and 2 are platforms. Mground is a variable to check if player is standing on any collision and is not in air. Vspd is vertical speed and hspd is horizontal speed.

I believe the issue is with this piece of code in horizontal collisions:
Code:
if (hcollide.collision ==1) {
        yplus = 0;
        //the number in brackets for abs indicated how many pixels high a slope can be
        while (place_meeting(x+hspd, y-yplus, obj_par_collision) && yplus<= abs(1*hspd)) {
            yplus += 1;
        }
Because it only checks for the solid collisions. But at the same time it's the beginning for a collision check in which I want the player not to collide with platforms horizontally. How can I tweak this code so it'll also include diagonal platforms and make the player go up them (like in Terraria when you make stairs for example) but at the same time keep it so I don't get stuck and collide horizontally?

Also last thing is that my player can go into the platforms and since it's neither above or under but right in the middle she doesn't fall down. How can I make her not walk into them?
 
S

Sokyogoku

Guest
Thanks for all that but they don't seem to have slope platforms. Each of them has slopes but solid slopes, not the ones that you can jump through (or fall through). And that's the only thing I would like to know how to make.

Even just to know how to tweak mine to apply going up and down jump through platform slopes.
 
Last edited by a moderator:

dannerz

Member
"Hi, I would like my game to have diagonal platforms." normally i use the step event.
if place_meeting(x+1,y,wall_obj)
if place_meeting(x+1,y-1,wall_obj)=0
{ x += 1; y-=1; }

use that with precise masks, it will move up one pixel per step. the sprite must have gradual curves, 1 pixel at a time.
 

Yal

🐧 *penguin noises*
GMC Elder
Thanks for all that but they don't seem to have slope platforms. Each of them has slopes but solid slopes, not the ones that you can jump through (or fall through). And that's the only thing I would like to know how to make.
That's probably the trickiest case, but I think it should be possible to solve if you think things through. You have a bunch of possible ways to interact with that kind of slope...
  • If you're on the ground, and move, and there's a slope ahead of you, you should move up and to the side.
  • If you're falling, and there's a slope in the way, you should land on top of it... but only if you're not already jumping through it, in which case you'd do nothing.
  • If you're moving upwards from jumping, you always ignore slopes.
It kinda feels like you could solve this by if-cases checking your vertical speed... and maybe modify you current moving left-and-right code. I think the easiest way to do that would be to check for slopes first, and THEN walls - and if you find a slope, you'd move up it at its incline. (You could have each slope object have local variables for this set in their create event so that you wouldn't need to do maths using its collision mask and stuff)
 
S

Sokyogoku

Guest
That's probably the trickiest case, but I think it should be possible to solve if you think things through. You have a bunch of possible ways to interact with that kind of slope...
  • If you're on the ground, and move, and there's a slope ahead of you, you should move up and to the side.
  • If you're falling, and there's a slope in the way, you should land on top of it... but only if you're not already jumping through it, in which case you'd do nothing.
  • If you're moving upwards from jumping, you always ignore slopes.
It kinda feels like you could solve this by if-cases checking your vertical speed... and maybe modify you current moving left-and-right code. I think the easiest way to do that would be to check for slopes first, and THEN walls - and if you find a slope, you'd move up it at its incline. (You could have each slope object have local variables for this set in their create event so that you wouldn't need to do maths using its collision mask and stuff)
Thank you! I think I know how to do this now (at least I hope so). Since it's late today (nearly 11pm) I'll try fixing it tomorrow and see if anything works :)
 

Yal

🐧 *penguin noises*
GMC Elder
If it doesn't work, we'll be here to help :3

...and if it DOES work, don't forget to mark your topic as solved~
 
S

Sokyogoku

Guest
If it doesn't work, we'll be here to help :3

...and if it DOES work, don't forget to mark your topic as solved~
I'm trying to swap the if statement for if it's not 0 (so no collision) and add in the if statement for collision 1 (solid). So far it only made the player go up slope platforms but she can't press down key to jump down them and the solid slopes don't work..... I'm still trying to figure out how I can do it while not completely rewriting the code.

Edit: Now it checks all the collisions but I can't pass through the diagonal platforms or jump down them though I can jump up onto them.
 
Last edited by a moderator:

jonjons

Member
Check out this tutorial to get an easy and versatile set of scripts :)
This was the most simple and easy way i found...
But the Real FPS go from 3000fps to 1000fps when climbing 45º slopes.
With 30 objects climb at the same time the fps shoud be something like 10
 

GMWolf

aka fel666
This was the most simple and easy way i found...
But the Real FPS go from 3000fps to 1000fps when climbing 45º slopes.
With 30 objects climb at the same time the fps shoud be something like 10
Fps does not scale linearly like that. A common mistake.
You should be calculating frame time instead. There is a 1/x relationship.
 

jonjons

Member
you mean something like this ? delta time ?
Code:
///---TIMER---

draw_set_halign( fa_center );
draw_set_valign( fa_middle );
draw_set_colour( c_yellow );
 
draw_text( 400, 20, "RunDelay: " + string (runDelay));
draw_text( 400, 35, "Facing: " + string (facing));
draw_text( 400, 50, "PlrSpeed: " + string (m_speed));

draw_text(90, 245, "DeltaTime = " + string(delta_time)); /////////////<------------------//-frame time--//------------------------
draw_text(50, 260, "State = " + string(state));
draw_text(45, 275, "FPS = " + string(fps));
draw_text(90, 290, "Real FPS = " + string(fps_real));
 

GMWolf

aka fel666
you mean something like this ? delta time ?
Code:
///---TIMER---

draw_set_halign( fa_center );
draw_set_valign( fa_middle );
draw_set_colour( c_yellow );
 
draw_text( 400, 20, "RunDelay: " + string (runDelay));
draw_text( 400, 35, "Facing: " + string (facing));
draw_text( 400, 50, "PlrSpeed: " + string (m_speed));

draw_text(90, 245, "DeltaTime = " + string(delta_time)); /////////////<------------------//-frame time--//------------------------
draw_text(50, 260, "State = " + string(state));
draw_text(45, 275, "FPS = " + string(fps));
draw_text(90, 290, "Real FPS = " + string(fps_real));
The problem is how you extrapolated your results. You can extrapolate frame time linearly, but not fps.
 

jonjons

Member
The problem is how you extrapolated your results. You can extrapolate frame time linearly, but not fps.
but... i dont know witch values to use, should it be delta time divided by frame time ?
I tested the game again and the frame rate only dropped below 30, with about 80 player clones climbing a slope... however it seems to drop quite large using bigger numbers like 3000.
 

GMWolf

aka fel666
but... i dont know witch values to use, should it be delta time divided by frame time ?
I tested the game again and the frame rate only dropped below 30, with about 80 player clones climbing a slope... however it seems to drop quite large using bigger numbers like 3000.
below 3o fps with 80 players? Are you using precise collisions or something?
 

jonjons

Member
below 3o fps with 80 players? Are you using precise collisions or something?
no just the usual move_contact_solid plus the place free for air / grounded
Code:
///----MOVEMENT-CONTROL----

vspeed += m_gravity;

//------------ground-air-set----------------------------

if ( ! place_free(x,y+1))
    {
        show_debug_message("trigger grav OFF !!!");
     grounded = true;
     //vspeed = 0;
    }
else
    {
        show_debug_message("trigger grav ON !!!");
     grounded = false;
     //vspeed += m_gravity;
    }

//------------------------------------------------------
//---------//----ground-movements-no-weapon-/-weapon----------//----

if (keyboard_check(vk_left) && grounded && canMove) //left move
    {
       move_contact_solid(90, m_step);
       move_contact_solid(180, m_speed);
       move_contact_solid(270, m_step+10);

       image_xscale = -1;
      
       if ( m_speed <= 3 )
       {
            if (weapon)
            {
               state = state.weapWalk;
            }
            else
            {
               state = state.onWalk;
            }
       }
       else if ( m_speed > 3 && ! weapon)
       {
            state = state.onRun;
       }
    }
else if (keyboard_check(vk_right) && grounded && canMove) //right move
   {
       move_contact_solid(90, m_step);
       move_contact_solid(0, m_speed);
       move_contact_solid(270, m_step+10);

       image_xscale = 1;
      
       if ( m_speed <= 3 )
       {
            if (weapon)
            {
               state = state.weapWalk;
            }
            else
            {
               state = state.onWalk;
            }
       }
       else if ( m_speed > 3 && ! weapon)
       {
            state = state.onRun;
       }
   }
 

GMWolf

aka fel666
no just the usual move_contact_solid plus the place free for air / grounded
Code:
///----MOVEMENT-CONTROL----

vspeed += m_gravity;

//------------ground-air-set----------------------------

if ( ! place_free(x,y+1))
    {
        show_debug_message("trigger grav OFF !!!");
     grounded = true;
     //vspeed = 0;
    }
else
    {
        show_debug_message("trigger grav ON !!!");
     grounded = false;
     //vspeed += m_gravity;
    }

//------------------------------------------------------
//---------//----ground-movements-no-weapon-/-weapon----------//----

if (keyboard_check(vk_left) && grounded && canMove) //left move
    {
       move_contact_solid(90, m_step);
       move_contact_solid(180, m_speed);
       move_contact_solid(270, m_step+10);

       image_xscale = -1;
     
       if ( m_speed <= 3 )
       {
            if (weapon)
            {
               state = state.weapWalk;
            }
            else
            {
               state = state.onWalk;
            }
       }
       else if ( m_speed > 3 && ! weapon)
       {
            state = state.onRun;
       }
    }
else if (keyboard_check(vk_right) && grounded && canMove) //right move
   {
       move_contact_solid(90, m_step);
       move_contact_solid(0, m_speed);
       move_contact_solid(270, m_step+10);

       image_xscale = 1;
     
       if ( m_speed <= 3 )
       {
            if (weapon)
            {
               state = state.weapWalk;
            }
            else
            {
               state = state.onWalk;
            }
       }
       else if ( m_speed > 3 && ! weapon)
       {
            state = state.onRun;
       }
   }
yes, but your sprites collisions masks -> Did you select precise on any of them. THis will absolutely tank your performance.
 

jonjons

Member
yes, but your sprites collisions masks -> Did you select precise on any of them. THis will absolutely tank your performance.
Ho i forgot... its Elipse ( circle shape ) on all animations, i also tried a costum sprite mask on the player object.
the frame drop could also be from move_contact_solid using a range of 1000 ?
 
Top