坦克对战游戏 AI 设计

坦克对战游戏 AI 设计

从商店下载游戏:“Kawaii” Tank 或 其他坦克模型,构建 AI 对战坦克。具体要求

  • 使用“感知-思考-行为”模型,建模 AI 坦克
  • 场景中要放置一些障碍阻挡对手视线
  • 坦克需要放置一个矩阵包围盒触发器,以保证 AI 坦克能使用射线探测对手方位
  • AI 坦克必须在有目标条件下使用导航,并能绕过障碍。(失去目标时策略自己思考)
  • 实现人机对战

成品图

在这里插入图片描述

具体实现

场景设计

利用官方教程Tanks! Tutorial里面的模型构建了自己的游戏场景。

坦克基类Tank

定义坦克的血量,射击方式

public class Tank : MonoBehaviour {
   
     private float hp =500.0f;
     public Tank()
     {
   
         hp = 500.0f;
     }

     public float getHP()
     {
   
         return hp;
     }

     public void setHP(float hp)
     {
   
         this.hp = hp;
     }
    
     public void shoot(TankType type)
     {
   
         GameObject bullet = Singleton<MyFactory>.Instance.getBullets(type);
         bullet.transform.position = new Vector3(transform.position.x, 1.5f, transform.position.z) + transform.forward * 1.5f;
         bullet.transform.forward = transform.forward; //方向
         bullet.GetComponent<Rigidbody>().AddForce(bullet.transform.forward * 20, ForceMode.Impulse);
     }
}

玩家player类

玩家类继承于坦克类,在player里定义移动和转向

public class Player : Tank{
   
   public delegate void DestroyPlayer();
   public static event DestroyPlayer destroyEvent;
   void Start () {
   
       setHP(500);
}

void Update () {
   
    if(getHP() <= 0)  
       {
   
           this.gameObject.SetActive(false);
           destroyEvent();
       }
}

   public void moveForward()
   {
   
       gameObject.GetComponent<Rigidbody>().velocity = gameObject.transform.forward * 30;
   }
   public void moveBackWard()
   {
   
       gameObject.GetComponent<Rigidbody>().velocity = gameObject.transform.forward * -30;
   }

   public void turn(float offsetX)
   {
   
       float x = gameObject.transform.localEulerAngles.x;
       float y = gameObject.transform.localEulerAngles.y +
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值