;Determine targetleaders x,y,z location relative to the enemy ship EntityParent TargetLeader,e\entity TargetX# = EntityX(TargetLeader,False) TargetY# = EntityY(TargetLeader,False) TargetZ# = EntityZ(TargetLeader,False) EntityParent TargetLeader,pvt ;-------------------------- ;Calculate Steering factor. The further away an entity is the higher the factor SteeringFactor# = EntityDistance(TargetLeader,e\entity)/1000 ;-------------------------- ;Rotate z based on x position (Roll the ship so target is near vertical axis) If targetX < -30*(SteeringFactor#-RandomFactor#) If TargetY < 0 ;Below and to the left, turn right e\roll# = e\roll# -(e\spz/TurningFactor%) Else e\roll# = e\roll# +(e\spz/TurningFactor%);Above and to the left, roll left End If End If If TargetX > 30*SteeringFactor# If TargetY > 0;Above And To the Right, turn Right e\roll# = e\roll# -(e\spz/TurningFactor%) Else e\roll# = e\roll# +(e\spz/TurningFactor%);Below and to the right, turn left End If End If ;-------------------------- ;Rotate x based on y (Climb or dive to face the target only if the target is near the ;vertical axis). Climb is the target is behind. If TargetZ < 0 Then e\pitch# = e\pitch# - (e\spx/TurningFactor%) Else If Abs(TargetX) <(100* (SteeringFactor#-RandomFactor#)) Then If TargetY > 30*SteeringFactor# Then e\pitch# = e\pitch# - (e\spx/TurningFactor%) End If If TargetY < -30*SteeringFactor# Then e\pitch# = e\pitch# + (e\spx/TurningFactor%) End If End If End If ;************* TURN AND MOVE THE SHIP ********************************** ;Rotate z based on roll position so craft flies horizontal If Abs(e\roll)<0.1 And Abs(e\pitch)<0.1 Then If EntityRoll(e\entity) < -5 ;e\roll# = e\roll# +(e\spz/TurningFactor%) TurnEntity e\entity,0,0,(e\spz/TurningFactor%) End If If EntityRoll(e\entity) > 5 ;e\roll# = e\roll# -(e\spz/TurningFactor%) TurnEntity e\entity,0,0,-(e\spz/TurningFactor%) End If End If e\pitch = e\pitch/1.1 e\roll = e\roll/1.1 e\yaw = e\yaw/1.1 TurnEntity e\entity,e\pitch#*FL\SpeedFactor,e\yaw#*FL\SpeedFactor,e\roll#*FL\SpeedFactor MoveEntity e\entity, 0, 0 ,e\spd*FL\SpeedFactor ;--------------------------
This is a small snippet of code from the AI function in my current project TRAFFIKA. It is also based on Elite and is coming along fantastically well.
It basically rolls the ship until the target is relatively vertical then pitches until it is infront. There are many other parts to this function to speed up, slow down, dodge, etc. But, I think this is the sort of thing you were after.
You can download a working copy of the game so far at http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=bigjohnno03142005145609&comments=no. It's about 40% complete and has come along way since I posted it. Check it out and let me know how you get along.
Oh, a few things to note;
e\entity - enemy entity
e\roll - enemy's roll
e\pitch - enemy's pitch
e\spx - enemy's climb speed
e\spz - enemy's pitch speed
e\randomfactor - random number to give each ship slightly different action. It is very noticable when groups of 5 or more are flying together.
e\targetleader - distanceof a pivot infront of the target which the enemy aims at. If it aims at the target it never hits it because its moving. e\targetleader is recalculated every round by taking into acount distances and speeds.