The brain of the computer-controlled plane will be a simple one. It will determine the angle difference towards the player plane. Then, it will turn towards that direction. If the player plane is in front of the computer controlled one, it will fire a shot.
1. Create a new method called
FollowPlayer
in thegame
class. The parameter is an object (usually the enemy plane).Method FollowPlayer:Int(obj:ftObject)
2. Determine the relative angle from the object towards the player's plane.
Local angle:Float = obj.GetTargetAngle(player,True)
3. If the angle is less than zero (left side of the object) turn the object counterclockwise. The factor is determined by the delta time divided by
16
.If angle < 0 Then obj.SetAngle(-eng.GetDeltaTime()/16.0,True)
4. If the player plane is on the right side, turn the object clockwise.
Else obj.SetAngle(eng.GetDeltaTime()/16.0,True) Endif
5. Now, if the absolute angle is less than
10
degrees, spawn a shot.If Abs(angle) <...