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

Need help with Boundary Limiting

I'm trying to code a limit that would make a spaceship drop from warp and stop before it reaches the boundary of the map. The game room has a width and height of 8k pixels. So here's what I'm thinking:
GML:
if (speed > 5){
    if (x > 7500){
        global.warp = false;
        friction = 5;
    }
}
While the ship is in warp it's speed is well over 5 so the first line is just to determine whether the ship is in warp. The second line is me trying to determine whether the x coordinate is over 7500. And if it is, the third line will set the global variable switch "warp" to false. That's part of a complicated system that makes it so the ship will go into warp(shortest explanation). The last line is setting a friction amount to 5. So that's it. The ship should stop once it reaches 7500. But it just keeps going to 8000 and collides with the boundary. Any ideas where I'm going wrong?
 

FoxyOfJungle

Kazan Games
Why do not you try:

Step Event:
GML:
var _border = 500;
if !point_in_rectangle(x, y, _border, _border, room_width-_border, room_height-_border) {
    global.warp = false;
    speed = (speed < 0) ? min(speed+0.1, 0) : max(speed-0.1, 0);
}
 
Last edited:
Top