- Unity Artificial Intelligence Programming
- Dr. Davide Aversa Aung Sithu Kyaw Clifford Peters
- 209字
- 2021-06-10 18:57:49
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.
推薦閱讀
- 連接未來:從古登堡到谷歌的網(wǎng)絡(luò)革命
- Web安全防護(hù)指南:基礎(chǔ)篇
- SEO 20日
- 工業(yè)控制網(wǎng)絡(luò)安全技術(shù)與實(shí)踐
- Truffle Quick Start Guide
- 物聯(lián)網(wǎng)之魂:物聯(lián)網(wǎng)協(xié)議與物聯(lián)網(wǎng)操作系統(tǒng)
- 物聯(lián)網(wǎng)檢驗檢測技術(shù)
- 局域網(wǎng)組建、管理與維護(hù)項目教程(Windows Server 2003)
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- 物聯(lián)網(wǎng)時代
- 通信簡史:從信鴿到6G+
- 圖解手機(jī)元器件維修技巧
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)技術(shù)實(shí)戰(zhàn)指南
- 5G+區(qū)塊鏈
- LwIP應(yīng)用開發(fā)實(shí)戰(zhàn)指南:基于STM32