官术网_书友最值得收藏!

The abstract FSM class

Next, we implement a generic abstract class to define the methods that our enemy tank AI class has to implement.

The code in the FSM.cs file is as follows:

using UnityEngine; 
using System.Collections; 
 
public class FSM : MonoBehaviour  
{ 
    //Player Transform 
    protected Transform playerTransform; 
 
    //Next destination position of the NPC Tank 
    protected Vector3 destPos; 
 
    //List of points for patrolling 
    protected GameObject[] pointList; 
 
    //Bullet shooting rate 
    protected float shootRate; 
    protected float elapsedTime; 
 
    //Tank Turret 
    public Transform turret { get; set; } 
    public Transform bulletSpawnPoint { get; set; } 
 
    protected virtual void Initialize() { } 
    protected virtual void FSMUpdate() { } 
    protected virtual void FSMFixedUpdate() { } 
 
    // Use this for initialization 
    void Start ()  
    { 
      Initialize(); 
    } 
     
    // Update is called once per frame 
    void Update ()  
    { 
      FSMUpdate(); 
    } 
 
    void FixedUpdate() 
    { 
      FSMFixedUpdate(); 
    } 
} 

The enemy tanks need only to know the position of the player's tank, their next destination point, and the list of waypoints to choose from while they're patrolling. Once the player tank is in range, they rotate their turret object and then start shooting from the bullet spawn point at their fire rate.

The inherited classes will also need to implement the three methods: Initialize, FSMUpdate, and FSMFixedUpdate.

主站蜘蛛池模板: 栖霞市| 泰和县| 龙门县| 临洮县| 辽宁省| 肥东县| 江阴市| 房产| 阿拉善右旗| 长兴县| 赤峰市| 吐鲁番市| 琼结县| 安远县| 疏附县| 邵阳县| 桦甸市| 米林县| 鱼台县| 东光县| 扶沟县| 定边县| 锡林郭勒盟| 北安市| 饶平县| 鹤山市| 昌黎县| 惠安县| 双峰县| 岑巩县| 黔西| 通州市| 于都县| 新民市| 鸡泽县| 隆德县| 沙田区| 北辰区| 汽车| 云林县| 宜城市|