Example #1
0
    private void Awake()
    {
        Gamekit3D.PlayerController playerController = FindObjectOfType <Gamekit3D.PlayerController>();

        if (playerController != null)
        {
            Target = playerController.transform.Find("HeadTarget");

            if (playerController.cameraSettings == null)
            {
                playerController.cameraSettings = this;
            }
        }
    }
Example #2
0
        public void FindTarget()
        {
            //we ignore height difference if the target was already seen
            PlayerController detectedTarget = PlayerScanner.Detect(transform, Target == null);

            if (Target == null)
            {
                //we just saw the player for the first time, pick an empty spot to target around them
                if (detectedTarget != null)
                {
                    Controller.animator.SetTrigger(SpottedTrigger);
                    Target = detectedTarget;
                    TargetDistributor distributor = detectedTarget.GetComponentInChildren <TargetDistributor>();
                    if (distributor != null)
                    {
                        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 (detectedTarget == null)
                {
                    TimerSinceLostTarget += Time.deltaTime;

                    if (TimerSinceLostTarget >= TimeToStopPursuit)
                    {
                        Vector3 toTarget = Target.transform.position - transform.position;

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

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

                        Target = detectedTarget;

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

                    TimerSinceLostTarget = 0.0f;
                }
            }
        }