waypoint creation on the fly?

Blitz3D Forums/Blitz3D Programming/waypoint creation on the fly?

stayne(Posted 2007) [#1]
I've been pondering spaceship AI over the last few days. My idea is for the AI ship to create it's own dogfighting waypoints on the fly. If the AI ship is approaching the player in attack mode, judging from entitydistance to the player it could create a waypoint behind and above/below/whatever the player in order to prevent a collision... then reacquire the player's position as the next waypoint.

Has this techniqe been done? Seem feasible?


jfk EO-11110(Posted 2007) [#2]
Common waypoint calculation algorythms take a lot of cpu time. In a dogfight with multiple flying objects even more.

I would start this way: Let'em fly around randomly in nice curves. Then make them check what's just in front of them, using linepick. If there is danger of collision, they may steer in order to prevent a collision more or less intelligent. The easiest way is to simple steer to one side.

There may still be a risk for them to crash in a more complex situation, but this probably is going to feel kind of realistic.


Matty(Posted 2007) [#3]
No need to even use a linepick - can simply use tformnormal as follows:

(pseudocode)


TFormNormal OtherCraftX-MyCraftX,OtherCraftY-MyCraftY,OtherCraftZ-MyCraftZ,0,MyCraft

;this transforms the vector which points from mycraft to othercraft from worldspace into mycraft's space

If TFormedZ()>0.7 then
;play with the 0.7 value, the closer it is to 1.0 (but less than 1.0) the closer the direction to the other craft is to 'dead ahead'

endif 



oh..also do an entitydistance check before the tform command as it may not be necessary to do the tform check if the other ship is far enough away.

if you are going to do a linepick then you can still use the above code, you would do so by placing the linepick within the if tformedz()>.. section, this reduces the number of linepicks you will need as there is no need to, for example, perform a linepick against a craft which is behind you.

Hope that is of some help.


Stevie G(Posted 2007) [#4]
I find tformpoint is good for this sort of thing. You can find where an enemy plane is relative to the position and direction the player is pointing ..

For example ....

tformpoint 0,0,0,e\Mesh, player\Mesh
if tformedz() > 0 then { enemy is in front }
if tformedz() < 0 then { enemy is behind }
if tformedx() < 0 then { enemy is to the left }
etc.....


You can also use it for bounding box collision checks ...

if abs( tformedz() ) < BoxZ and abs( tformedx() ) < BoxX and abs( tformedy() < BoxY then { a collision has occured }


Where BoxX, Y & Z are the ( Players bounding box width + Enemy bounding box width ) * .5


[EDIT] Matt posted while I was but both are relavant and very useful.

Stevie