PDA

View Full Version : How do I move something randomly within a boundary?


Chief413
11-02-2009, 11:44 AM
I'm trying to create a game, but I'm having difficulties trying to get the character move randomly, while staying within a set boundary. I've set it so that it uses the random number function to move and such, but sometimes it simply moves too far and disappears. Would this be fixable by using an if/else of sorts, or what?

x2495iiii
11-02-2009, 02:39 PM
Yes. By finding out the exact dimensions of the area you'd like the object to move, then making an if/else if statement which checks to see if the randomly generated movement will make the object move outside that boundary and generate a new one if it will.