ballistics calculation algorithm for AI : Java-Games
This is a discussion on ballistics calculation algorithm for AI within the Java-Games forums in Other Technologies category; 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 ...
| Java-Games Discussions about downloadable java games and other games developed in java |
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
| On Monday 20 October 2008 15:59, Lacrymology wrote: > 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- |


