unity c# ai 随机漫游 攻击 避让

本文介绍了Unity中使用C#实现AI的随机漫游、攻击以及避让功能。首先定义了AI行为,然后详细阐述了如何获取随机方向并设置随机间隔以增加行为的不确定性,接着讨论了通过周期更新来提高AI响应效率,最后讲解了执行这些行为的步骤。
摘要由CSDN通过智能技术生成

定义

        //敌人类型枚举 有策划人员选择
        public EnemyType enemyType = EnemyType.PlayerTest;
        public string enemyName;
        //平均每次随机方向持续的时间,use it's 50%-150%
        public float m_randomDirectionAvergeTime=5;


        //主角游戏对象
        private GameObject[] players;

        //敌人状态 普通状态 旋转状态 奔跑状态 追击主角状态 攻击主角状态
        private const int EMEMY_NORMAL = 0;
        private const int EMEMY_ROTATION = 1;
        private const int EMEMY_RUN = 2;
        private const int EMEMY_CHASE = 3;
        private const int EMEMY_ATTACK = 4;

        //记录当前敌人状态 根据不同类型 敌人播放不同动画
        private int state;
        //旋转状态,敌人自身旋转
        private int rotation_state;
        //记录敌人上一次思考时间
        private float aiThinkLastTime;
        //记录敌人上一次RandomDirection
        private float aiThinkRandomDirectionLastTime;
        //每次随机方向持续的时间
        public float randomDirectionTime=5;
        //the Direction setted from last think,which will be kept during randomDirectionTime
        public int randomLastDirection=0;

        public TankControl tankControl;

        //15
        public float MinShootRange=15;
        //<=30
        public float MaxShootRange=20;
        //5
        public float MaxAvoidDistance=5;
        //
        
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值