Don't let the length of the tread frighten you.
I'm working on a game much like the old DOS classic Scorched Earth.
http://www.rydeman.com/erik/tanks3.html
I have now come to a point in development when it would be a good idea to start poking the AI for opponents a little.
What I need is for the enemy tank to calculate the rotation/power combo that will hit another tank bullseye. After that I'll add some randomness to that depending on difficulty.
Anyway, here's how I calculate the projectile's path (all the hittest crap etc. of the function removed of course):
All values are constant except for rotation, power and count.Code:on(enterFrame){ count++ this._x =startX+power*count*Math.cos(-rotation*Math.PI/180)*AR; this._y =startY-(power*count*Math.sin(-rotation*Math.PI/180)-0.5*gravity*count*count); }
Again, the task:
Getting the best power/rotation combo!
For those who wish to know what these values do:
Power varies between 0 and 100 but is multiplied with 0.21875 above. you do not need to know this.
rotation varies between 0 and 180 but we can limit it to 0-90 by comparing x-coords or maybe 45-90 by rationalising.
statX/startY= the position of the tank fireing.
this._x/this._y = the position we want the projectile to be at ie the other tank's position.
AR=air resistance(0.95).
gravity = the acceleration down of pixels/(frame*frame) (=0.5)
Ideas for solving it (Allah knows I've tried):
Getting rid of count by replacement and put the derivative of rotation as a function of power to 0. (or the other way around)
Making power a high constant and just calculating the rotation. this will look kinda bad but a possible if-all-else-fails solution.
or if all else *really* fails making a few thousand calculations comparing all combos and picking the best one.
Anyone that works out a *good working* solution *will* be mentioned in the credits!
Even if you don't have the time to have a go at it, ideas for solving it or comments about the game so far is greatly appreciated.
[Edited by Rydeman on 07-15-2001 at 04:49 PM]





Reply With Quote