I'm working on a space game, and the one thing I'm really worried about is AI. I have no idea how to do space AI.
Can anyone help with a few tips and pointers?
Can anyone help with a few tips and pointers?
Function UpdateAI() For a.ai = Each ai If a\static = False And a\angry = False ;if this AI actually moves in the game...and is not attacking For this.aiwaypoint = Each aiwaypoint If this\num = a\nextwaypoint ; aivx# = EntityX( this\mesh, True ) - EntityX( a\mesh, True ) aivy# = EntityY( this\mesh, True ) - EntityY( a\mesh, True ) aivz# = EntityZ( this\mesh, True ) - EntityZ( a\mesh, True ) AlignToVector( a\mesh, aivx#, aivy#, aivz#, 3, 0.03 ) ;enemy has reached the destination...where to next? If EntityDistance(a\mesh,this\mesh) < 200 ;next waypoint choice logic here - time to bank maybe? slow down? etc. a\nextwaypoint = a\nextwaypoint + 1 EndIf ;last waypoint in the loop reached so go back to the first one If a\nextwaypoint = a\lastwaypoint Then a\nextwaypoint = 1 ;Thrust logic MoveEntity a\mesh,0,0,a\thrust# EndIf Next EndIf Next End Function
Function avoid_entity( scr_entity, dest_entity, rate#, spd# ) If EntityDistance(scr_entity,dest_entity) < 300 Then MoveEntity scr_entity,0,0,spd# dist1# = EntityDistance(scr_entity,dest_entity) MoveEntity scr_entity,0,0,-spd# TurnEntity scr_entity,0,rate#,0 MoveEntity scr_entity,0,0,spd# dist2# = EntityDistance(scr_entity,dest_entity) MoveEntity scr_entity,0,0,-spd# TurnEntity scr_entity,0,-2*rate#,0 MoveEntity scr_entity,0,0,spd# dist3# = EntityDistance(scr_entity,dest_entity) MoveEntity scr_entity,0,0,-spd# If dist1# > dist2# And dist1# > dist3# Then TurnEntity scr_entity,0,rate#,0 If dist2# > dist3# And dist2# > dist1# Then TurnEntity scr_entity,0,2*rate#,0 Return True Else Return False EndIf End Function