Legacy GM [Solved]Confused on how to get a jump through platform

C

Cmtrain

Guest
So I am using Shaun Spalding's platforming engine and after many tries I can't figure out how to get a jump through platform to work. I know Shaun has a tutorial on it but I don't like how it gets rid of the collision box, because I want to have enemies on top of them. If any one haves any ideas I would like to hear them.

Code below.

This is in the player object, step event.
dont_move is used to stop the player when they are in a trap.

//Jumping-----------------------------------------------------
if(place_meeting(x,y+1,obj_ground)&& !dont_move){

vsp = key_jump * -jumpspeed;

}
//Horizontal Collision-------------------------------------
if(place_meeting(x+hsp,y,obj_ground)){

while(!place_meeting(x+sign(hsp),y,obj_ground)){
x += sign(hsp);
}
hsp = 0

}
else if(!dont_move)
x += hsp;
//Vertical Collision--------------------------------------
if(place_meeting(x,y+vsp,obj_ground)){

while(!place_meeting(x,y+sign(vsp),obj_ground)){
y += sign(vsp);
}
vsp = 0;

}
else if(!dont_move)
y += vsp;
 

Mick

Member
Getting rid of the collision box is a clumsy hack more than a solution. It can be done in a more elegant way. There was recently a topic about this, there I explained how I do it, it's actually quite simple. In my post I just also explain how I have things setup.

https://forum.yoyogames.com/index.p...e-using-collision_-functions.6260/#post-45688

Basically you should check for platform collisions at feet level only when the player or object has a downward movement. If there is a collision and there was no collision in the previous step's position then consider the object to have touched ground.
 
Last edited:

NightFrost

Member
I do it almost like WitchMaster does, except instead of recalling previous step I compare y-positions instead; if player y is smaller than (above) platform y, they are falling onto it from above, and collision should stop them. There's one gotcha you need to be aware of: don't place platforms in a manner that allows player overlap more than one while falling. There's a chance collision detection picks the wrong one, giving unintended results.
 

TheouAegis

Member
@WitchMaster 's use of instance_position() doesn't have the unwanted caveat of platform placement restrictions. Unless you're silly enough to actually overlap your platforms, there would only ever be one platform at a particular point.

HOWEVER...........
Code:
var inst_platform = instance_position( x-width/2, y, obj_platform);
  if(inst_platform == noone)
    inst_platform = instance_position( x+width/2, y, obj_platform);
  if( inst_platform != noone )
  {
      var inst_platform_above = instance_position( x-width/2, yprevious, inst_platform);
      if(inst_platform_above == noone)
        inst_platform_above = instance_position( x+width/2, yprevious, inst_platform);
You should have checked for a collision above with inst_platform, not obj_platform. That would even have allowed for overlapping platforms.

With that said, you don't need those latter instance checks anyway.
Code:
var inst_platform = instance_position( x-width/2, y, obj_platform);
  if(inst_platform == noone)
    inst_platform = instance_position( x+width/2, y, obj_platform);
  if( inst_platform != noone )
  {
      if bbox_bottom - vspd < inst_platform.bbox_top

And personally I'm a fan of bbox_left and bbox_right instead of -width/2 and +width/2 -- gives more flexibility.
 

NightFrost

Member
Ah, instance_position. Funnily enough, my older platformer code appears to use that, but I've regressed into using instance_place in newer one. I wonder why I've actually made the change, it's not like one extra collision check makes any difference in speed.

EDIT - Apparently I had made the change because of collapsible platforms formed of very narrow pieces. With just corner checks with instance_position, it would be possible to stand directly above a piece and clip through because both checks would miss it.
 
Last edited:
C

Cmtrain

Guest
Thanks for all the help. I took WitchMaster's idea of checking for platform collisions only when the player has downward movement. This allows the player to collide with the platform from below, so when this happens I add the player's (jump speed)/2 to force the player out of the platform and have them land on top. Its rough around the edges but it gives me something to work with for the time being. Thanks again for all the help guys.:)
 
Top