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

Platformer pushable solid

N

nlolotte

Guest
Hi guys,

I've recently built push able solids into my platformer engine. They work some what well but my only problem is if the solids are stacked on top of each other and you push left, it will move the below push solid as well dragging the character and not letting the top solid fall down. This doesn't happen when you do the same thing pushing right though?

Here is my code:

obj_player step event

Code:
//Push
if (place_meeting(x-2,y,obj_solid_push)) && (lkey) && place_meeting(x,y+1,obj_solid)
{
    anim = "push";
    i = instance_nearest(x-2,y,obj_solid_push);
    with i
    {
        if !place_meeting(x-1,y,obj_solid)
        {
            x -= 1;
        }
    }
}

if (place_meeting(x+2,y,obj_solid_push)) && (rkey) && place_meeting(x,y+1,obj_solid)
{
    anim = "push";
    i = instance_nearest(x+2,y,obj_solid_push);
    with i
    {
        if !place_meeting(x+1,y,obj_solid)
        {
            x += 1;
        }
    }
}
Some images for reference

Pushing from left (bottom block moves too):


Pushing from right (works fine)

 

jo-thijs

Member
Why do you use instance_nearest?
Wouldn't instance_place or instance_position or something like that work waaay beter?
 
N

nlolotte

Guest
I used it to look for the nearest push block and apply the pushing to that instance, is that not the best way to approach it? I'll try your suggestion now. Thanks for the quick reply :)
 
N

nlolotte

Guest
It works! Thanks for the quick answer man, feeling slightly stupid now. Fairly new to all this. Have a nice day dude.
 
Top