public TargetFollower(TargetDistributor owner)
 {
     distributor   = owner;
     requiredPoint = Vector3.zero;// 默认 是 玩家当前的位置
     requireSlot   = false;
     assignedSlot  = -1;
 }
Example #2
0
            public TargetDistributor distributor;          //定义一个分配器

            public TargetFollower(TargetDistributor owner) //目标跟随
            {
                distributor   = owner;                     //将owner赋给分配器
                requiredPoint = Vector3.zero;              //给需求点赋值
                requireSlot   = false;                     //关闭需要位置
                assignedSlot  = -1;                        //给分配位置赋值
            }
        public void FindTarget()
        {
            //we ignore height difference if the target was already seen
            PlayerController target = playerScanner.Detect(transform, m_Target == null);

            if (m_Target == null)
            {
                //we just saw the player for the first time, pick an empty spot to target around them
                if (target != null)
                {
                    m_Controller.animator.SetTrigger(hashSpotted);
                    m_Target = target;
                    TargetDistributor distributor = target.GetComponentInChildren <TargetDistributor>();
                    if (distributor != null)
                    {
                        m_FollowerInstance = distributor.RegisterNewFollower();
                    }
                }
            }
            else
            {
                //we lost the target. But chomper have a special behaviour : they only loose the player scent if they move past their detection range
                //and they didn't see the player for a given time. Not if they move out of their detectionAngle. So we check that this is the case before removing the target
                if (target == null)
                {
                    m_TimerSinceLostTarget += Time.deltaTime;

                    if (m_TimerSinceLostTarget >= timeToStopPursuit)
                    {
                        Vector3 toTarget = m_Target.transform.position - transform.position;

                        if (toTarget.sqrMagnitude > playerScanner.detectionRadius * playerScanner.detectionRadius)
                        {
                            if (m_FollowerInstance != null)
                            {
                                m_FollowerInstance.distributor.UnregisterFollower(m_FollowerInstance);
                            }

                            //the target move out of range, reset the target
                            m_Target = null;
                        }
                    }
                }
                else
                {
                    if (target != m_Target)
                    {
                        if (m_FollowerInstance != null)
                        {
                            m_FollowerInstance.distributor.UnregisterFollower(m_FollowerInstance);
                        }

                        m_Target = target;

                        TargetDistributor distributor = target.GetComponentInChildren <TargetDistributor>();
                        if (distributor != null)
                        {
                            m_FollowerInstance = distributor.RegisterNewFollower();
                        }
                    }

                    m_TimerSinceLostTarget = 0.0f;
                }
            }
        }
Example #4
0
        public void FindTarget()
        {
            PlayerController target = playerScanner.Detect(transform, m_Target == null);

            if (m_Target == null)
            {
                if (target != null)
                {
                    m_Controller.animator.SetTrigger(hashSpotted);
                    m_Target = target;
                    TargetDistributor distributor = target.GetComponentInChildren <TargetDistributor>();
                    if (distributor != null)
                    {
                        m_FollowerInstance = distributor.RegisterNewFollower();
                    }
                }
            }
            else
            {
                if (target == null)
                {
                    m_TimerSinceLostTarget += Time.deltaTime;

                    if (m_TimerSinceLostTarget >= timeToStopPursuit)
                    {
                        Vector3 toTarget = m_Target.transform.position - transform.position;

                        if (toTarget.sqrMagnitude > playerScanner.detectionRadius * playerScanner.detectionRadius)
                        {
                            if (m_FollowerInstance != null)
                            {
                                m_FollowerInstance.distributor.UnregisterFollower(m_FollowerInstance);
                            }


                            m_Target = null;
                        }
                    }
                }
                else
                {
                    if (target != m_Target)
                    {
                        if (m_FollowerInstance != null)
                        {
                            m_FollowerInstance.distributor.UnregisterFollower(m_FollowerInstance);
                        }

                        m_Target = target;

                        TargetDistributor distributor = target.GetComponentInChildren <TargetDistributor>();
                        if (distributor != null)
                        {
                            m_FollowerInstance = distributor.RegisterNewFollower();
                        }
                    }

                    m_TimerSinceLostTarget = 0.0f;
                }
            }
        }