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

GameMaker [SOLVED]Conditional movement while checking for collisions

I wrote a dash ability for my character. Everything works except for the collision checks.

When a succesful dash takes place I call either of the functions "scrDashLeft" or "scrDashRight":

Code:
with (objPlayer)
{
   for (var i = 0; i < 10; i += 1) x -= 0.5;
 
       // Colliding horisontally?
   if (place_meeting(x+hsp,y, objWall))
   {
       while (!place_meeting(x+sign(hsp),y,objWall))
       {
       x = x + sign(hsp);
       onWall = false;
       }
       hsp = 0;
       onWall = true;
   }
   x = x + hsp;
 
       // Colliding vertically?
   if (place_meeting(x, y+vsp, objWall))
   {
       while (!place_meeting(x,y+sign(vsp),objWall))
       {
           y = y + sign(vsp);
       }
 
       vsp = 0;
   }
   y = y + vsp;
}
I guess what I need is something like:

Code:
Increment/decrement X correct number of steps unless a wall is hit.
If a wall is hit... stop next to the wall.
All input is appreciated!

Edit: I've been fiddling with DO / WHILE loops but I always manage to create endless loops.
Edit2: Yes... I'm quite noobish.
 
Last edited:

TheouAegis

Member
You need brackets properly placed.

for (var i = 0; i < 10; i += 1) x -= 0.5;

That's just a really, really slow way of doing x-=5 with no collision checks until after you move.

Code:
repeat dash_distance {
    if !place_meeting(x-1,y,objWall) x--;
    else break;
}
Although that's more of a blink than a dash. But whatever.
 
Top