/*
     * reaciton is to be astonished for 0.5 seconds before assuring that player is defintely within line of sight or not
     * if player is defenitely seen, pursue player, else go to where player was last seen, cautiously.
     */
    IEnumerator ReactToDetection(RaycastHit2D playerLastSeen)
    {
        _coneRender.ActivateState(_suspicion);
        detectPlayer = new RaycastHit2D();

        yield return(StartCoroutine(Baffled()));

        SetNavigationState(playerLastSeen, detectPlayer);

        StartCoroutine(_pathFinder.StartPursuit());
    }
Пример #2
0
 /*
  * behaviour if does not find player
  * Guard finished the previously patrolled route
  * search for route to the end point and patrols
  */
 public IEnumerator FinishPatrol()
 {
     _detector.SeenPlayer = false;
     gameObject.layer     = 9;
     _coneRender.ActivateState(Color.grey);
     SetSpeed(PatrolSpeed);
     SetGoal(_patrolBehav.ReturnNodeInRouteAt(_patrolBehav.ReturnPatrolRouteLength() - 1));
     _routeToGoal = CalculateRouteToDestination();
     yield return(StartCoroutine(NavigateToGoal(true)));
 }
    /**
     * Creates 4 points for vision cone shape, left and right are just reverse of each other
     * Get the appropriate compoenent and assign them starting values
     */
    private void SetUpVisionCone()
    {
        _leftVision.Add(new Vector2(-0.2f, 0.5f));
        _leftVision.Add(new Vector2(-5f, 1.6f));
        _leftVision.Add(new Vector2(-5f, -0.8f));
        _leftVision.Add(new Vector2(-0.2f, _detection.GetEyeDistance()));


        for (int i = 0; i < 4; i++)
        {
            var rightEye = Vector2.Scale(_leftVision.ElementAt(i), new Vector2(-1f, 1f));
            _rightVision.Add(rightEye);
        }

        _visionCone        = GetComponent <PolygonCollider2D>();
        _visionCone.points = _rightVision.ToArray();

        _coneRender = GetComponent <VisionConeRender>();
        _coneRender.SetConeShape(_visionCone.points);
        _coneRender.ActivateState(_blind);
    }