 |
|
| Computers Forum Index » Computer - Games Programming (Algorithms) » ballistics calculation algorithm for AI... |
|
Page 1 of 1 |
|
| Author |
Message |
| Lacrymology... |
Posted: Mon Oct 20, 2008 7:59 pm |
|
|
|
Guest
|
I'd like to calculate the throw needed to throw a ball to a certain
point, for my AI. The terrain is a heightmap, but the wanted position
might not be on the floor, since our game has a number of platforms
and gadgets of various types. Also I'd need to avoid obstacles like
trees and the such.
The only way I could think of so far is making a few random throws
with ghost balls in the overall desired direction, and iterate a
hundred or so times per tick to see if we ever get there, but this is
really really stupid. There should be some way of at least calculating
a range of possible values. Can anyone point me somewhere?
Thanks |
|
|
| Back to top |
|
|
|
| Paul E. Black... |
Posted: Tue Oct 21, 2008 9:48 pm |
|
|
|
Guest
|
On Monday 20 October 2008 15:59, Lacrymology wrote:
Quote: I'd like to calculate the throw needed to throw a ball to a certain
point, for my AI. The terrain is a heightmap, but the wanted position
might not be on the floor, since our game has a number of platforms
and gadgets of various types. Also I'd need to avoid obstacles like
trees and the such.
The only way I could think of so far is making a few random throws
... [PEB]
I start with the equation for a parabola (I assume your game works
with the standard approximation of constant gravity straight down).
That is, given the angle and force, where will it hit (at the same
height)? Invert it to get angle given force and target (including
height). (Or force given angle and target.)
Then add wind and air friction, if your game includes it.
Take derivative to find the maximum height. From this you can
compute, say, an angle to just clear an obstacle (assuming it is at
the apogee).
Better yet, find an equation giving the height given (a) distance from
the beginning, target, force, and angle. You can "walk" the path to
the target checking that the path clears each obstacle.
If the setting is in a cave, or more generally if there are obstacles
from above (e.g. roofs or stalactites) in addition to obstacles from
below (e.g. trees or hills), you can keep track of the maximum and
minimum angles that clears each one. If max is below min, you don't
have a clear shot.
If the equation ever gets too tough, you can stop with what you have
to find starting values. You could then try your ghost balls to
account for air friction or other things.
-paul- |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Thu Nov 26, 2009 12:12 am
|
|