Edge running

Post Reply
oneavg
Posts: 1
Joined: Sun Dec 02, 2007 9:09 pm

Edge running

Post by oneavg »

I'm having some issues. I don't know if it is me or the computer, but here is my problem.
my code:
destX = (dx * .05) + (r.nextDouble() * (dx * .9)); // choose random destination
destY = (dy * .05) + (r.nextDouble() * (dy * .9));
This is suppoessed to keep my units away from the edge of the battle screen, unforntally it doesn't seem to work. I have tired several different numeric value, but i can't seem to fix the issue. I have thought about hard codeing number values in, but that is a bad idea if you change the area size. I beleive the area size is roughly 50 x 50. Any ideas?
oneavg
Alphie
Posts: 2
Joined: Wed Nov 28, 2007 2:14 am
Location: Atlanta Ga

Post by Alphie »

try using nextInt() instead of nextDouble()

pick a distance from the edge you want, say 5 and do something like


destX = 5+(Double)r.nextInt(dx-5); etc.


If you are picking a random destination, it probably doesn't have to be smaller grained than an int.
User avatar
adum
Posts: 392
Joined: Thu Apr 19, 2007 12:49 pm
Contact:

Post by adum »

you have a good idea, you just need to make your distance from the edge greater, as 0.05 * boardsize is probably too small. (remember, a small amount of randomness is applied to all movement orders, and this will probably negate your edge avoidance.) something like alphie suggested will work fine, and is probably better because it will keep about a range away from the edge no matter the board size.

adum
Post Reply