Quote:
Originally Posted by jdeisenberg
Argh. Never mind; I figured it out by having the penguin "say" its distance from the fish and the tree.
Here's the problem: since they are never exactly equal, the penguin will keep moving until it is very near the fish. The next move takes the penguin to the other side of the fish, so it has to move back. They're never exactly equal.
The correct way to do it is:
Code:
penguin.moveto palmtree
penguin.turn to face fish
penguin.move (penguin.distance to fish / 2) towards fish
|
You might try storing the distance to move in a variable. Initialize that variable to half the distance to the fish. Go into a loop. During each iteration, make one move toward the fish moving the distance that is currently stored in the variable. Then replace the value in the variable by half the distance to the fish before starting another iteration of the loop.
Theoretically, the penguin would never get to the fish. Practically, however, you could allow it to get arbitrarily close before terminating the loop.
To keep the animation from being jerky, cause each move to start and end abruptly.
Dick Baldwin
Free Alice tutorials:
http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials:
http://www.dickbaldwin.com/toc.htm