AI 人工智能 探索 (六)

这次我为 角色 attribute 添加了 多个属性

其中 att 是 好人 坏人 等属性, 显然 数字不同 就要打起来。

grade 是智商属性 ,今天先做了 3的智商。也就是小兵智商。碰到就打 逃也要追着打

distance 是 可攻击距离 ,如果两个物体超过了 这个距离 就继续移动 小于这个距离就打

其他三个不解释,都能理解

    private Transform otherTransforms;//碰撞对方
    private bool track = true;//是否 可以 追踪
    private bool continued = true;//是否持续
    //根据智商等级 来控制 角色做哪些事情
    void OnGradeIQ(int i, float distance,Transform otherTransform)//智商等级 距离 对方
    {
        if (this.transform.GetComponent<Attribute>().distance > distance)//范围在 攻击距离中,不用继续追踪
        {
             this.transform.GetComponent<SteeringAgentComponent>().m_maxSpeed = 0; 
          //可以攻击,提交给update 发射
            //速度变零
            track = false;
            continued = true;
            otherTransforms = otherTransform;
        }
        else {
            track = true;
        }

        if (track && continued)//如果可以追踪
        {
            continued = false;//移动 
            //速度恢复 
            this.transform.GetComponent<SteeringAgentComponent>().m_maxSpeed = 11;
            switch (i)
            {
                case 0: 

                    break;
                case 1:

                    break;
                case 2:

                    break;
                case 3:
                     //智商级别三,小兵级别。敌不动 我不动,敌若动,我死磕
                    //寻找 对方 坐标
                    this.transform.GetComponent<Interaction_Patrol>().m_patrolNodes[0] = otherTransform.gameObject ;
                    this.transform.GetComponent<Interaction_Patrol>().OnStopFind();
                     
                    break;
                case 4:

                    break;
                case 5:

                    break;
                default:

                    break;
            }
        }
    }

还是昨天的补充,智商三 意思就是,两个角色距离没到distance,智商是3 就开始 跟踪,

        //可以攻击
        if (track == false && continued == true)
        {
            xx += Time.deltaTime;
            if (xx>2)
            {
               xx = 0;
               Transform transforms = Spawner("daodan");//导弹
               transforms.GetComponent<Missile>().OnPosition(this.transform, otherTransforms);
            }
        }

update 下 我简单的 测试下,也就是说 上一段代码符合攻击,那么就 开始射击,没有做血逻辑,先面板中调试ok

先创建一个 按照 固定点走

然后第二个 也是按这个点走,因为他们离得比较远

他们近了,他们改变行走路向 目标对方

他们继续 靠近对方 为了到达 可以 射击的 距离

射击!!! 怎么样,有意思吧。下一节 继续补充 其他 智商的 ai。

原文地址:https://www.cnblogs.com/big-zhou/p/4151465.html