So I guess my question is a simple as what do I need to do to calculate
movement along a curved path?
Another trick, rather than ‘hard-coding’ it to a trigonometrically-calculated
ellipse, is to make the objects move around on their own, and gravitate
towards the center.
In other words, each object has the following:
x,y - position on the screen
xm,ym - momentum (negative for left/u; positive for right/down)
To move the objects during even frame (event loop cycle), just do:
x = x + xm;
y = y + ym;
To make them ‘gravitate’ towards something, you can do:
if (x > home_x)
xm–;
else if (x < home_x)
xm++;
if (y > home_y)
ym–;
else if (y < home_y)
ym++;
In other words “if I’m suddenly on the left of the thing I’m homing-in-on,
start heading to the right, to go towards it!”
This, of course, ends up being far less accurate than using trig, but it
can look more ‘realistic’, I guess you could say. ;^)
This is how I’ve done homing-missiles in the past. If you’re clever,
you can even do those cheesy movie stunts where you (e.g., a space-ship
being chased by the above-explained homing missiles) head closer and
closer to some big deadly object, and then suddenly change course.
The missile’s “xm/ym” changes don’t happen quick enough, and the missile
crashes into the object, instead of you. (How cheesy ;^) )
Something is telling me this all comes down to basic trigonometry,
right?
Heheh… it really depends. If you want something that’ll orbit the
same no matter where the ‘center’ is, or what’s going on around it,
then yeah, using trig (or heck, an array filled with some pre-calc’d
trig values) is what you want. “Options” (little defense doo-dads
around a space ship) is one example.
If you want something that might be more inaccurate (hey, there can
be benefit to inaccuracy!), then you can use my hack above.
YMMV. IANAPGP[*]
-bill!On Wed, Sep 24, 2003 at 04:55:45PM -0400, Chris Heller wrote:
–
bill at newbreedsoftware.com Got kids? Get Tux Paint!
http://newbreedsoftware.com/bill/ http://newbreedsoftware.com/tuxpaint/
[*] I am not a professional game programmer. [+]
[+] For godsake, someone! HIRE ME!! :^(