O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — following the player

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 the game 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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required