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

Legacy GM {Solved} What's a good way to ensure that enemies and characters dont fall out of the room

J

Jamsawamsa

Guest
Just wanted to know what would be a good way to ensure that characters stay within the bounds of a room for a 2d platformer.

One of the ways that I was thinking off was lining the 4 sides of a room with a wall or tile object but this seems to me to be a rather inefficient way of achieving this. Does anyone know of a better way to implement this?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Just check the x value before doing any moving...

Code:
if (x + movespeed) > 0 && (x + movespeed) < room_width
{
// move
}
else
{
// Outside the room so do something else like change direction
}
That's just a very basic example and the actual solution will depend on your movement code, but the idea is the same. Check the position that the instance will move TO and if it's outside the room bounds, don't let it move.
 
J

Jamsawamsa

Guest
oh thanks! both of the solutions are exactly what i needed! =D
 
Top