[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Swarm-Support] Re: Re: Walk to a spot on a 2d grid?
From: |
Jurgen van der Pol |
Subject: |
[Swarm-Support] Re: Re: Walk to a spot on a 2d grid? |
Date: |
Tue, 20 Apr 2004 20:19:18 +0200 |
Hi,
firmly in the trivia dep't: after pursuing the vector/angle route for a
while, decided that it is too cumbersome. My final solution to
purposefully step around a 2d grid is simply to set a normalised vector
towards the destination x, y by taking the sign of the delta between
destination and origin. Like
while (not at destination)
{
xStep = sign(xDestination - xPosition); // gives me either -1,
0 or 1
ystep = sign(yDestination - yPosition); // gives me either -1,
0 or 1
xPosition = xPosition + xStep; // step
yPosition = yPosition + yStep; // step
}
I fancied this up further by allowing for world wrap-around to ensure
the shortest route. Crude, but it works (like Russian spacegear).
Anybody brave enough to want to have a look at my botch job (plain
vanilla ObjC, no Swarm in it (yet!)), just holler & start cringeing.
Hey, I'm proud I even got this far!
Cheers,
Jurgen.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Swarm-Support] Re: Re: Walk to a spot on a 2d grid?,
Jurgen van der Pol <=