// Start is called before the first frame update
    void Start()
    {
        viewDistanceVar = viewDistance;

        visionConeScript = Instantiate(visionConePrfb, visionConeGroup.transform).GetComponent <VisionCone>();
        visionConeScript.SetFov(fov);
        visionConeScript.SetViewDistance(viewDistanceVar);
    }
Beispiel #2
0
 // Start is called before the first frame update
 void Start()
 {
     player = GameObject.FindGameObjectWithTag("Player").transform;
     anim   = GetComponent <Animator>();
     agent  = GetComponent <NavMeshAgent>();
     col    = GetComponent <CapsuleCollider>();
     cone   = GetComponentInChildren <VisionCone>();
 }
Beispiel #3
0
 void Start()
 {
     Debug.Log("Startin' vision cone up.");
     viewMesh            = new Mesh();
     viewMesh.name       = "View Mesh";
     viewMeshFilter.mesh = viewMesh;
     StartCoroutine("FindTargetsWithDelay", .2f);
     vision = GetComponent <VisionCone>();
 }
Beispiel #4
0
 private void OnEnable()
 {
     player = GameObject.FindGameObjectWithTag("Player").transform;
     anim   = GetComponent <Animator>();
     agent  = GetComponent <NavMeshAgent>();
     col    = GetComponent <CapsuleCollider>();
     cone   = GetComponentInChildren <VisionCone>();
     WalkToNextPatrolPoint();
     anim.SetTrigger("IsEnabled");
 }
Beispiel #5
0
    //NavMeshObstacle obstacle;

    // Use this for initialization
    void Awake()
    {
        manager = FindObjectOfType <GameManager>();
        player  = GameObject.FindWithTag("Player");
        vision  = transform.GetChild(0).gameObject.GetComponent <VisionCone>();
        degs   /= Random.Range(3, 5);
        //obstacle = transform.GetChild(0).GetComponent<NavMeshObstacle>();
        //obstacle.enabled = false;
        //KillLights();
    }
    //Events
    void Awake()
    {
        //Set up the state machine
        stateMethods.Add(State.searching, WhileSearching);
        stateMethods.Add(State.attacking, WhileAttacking);

        //Get components
        visionCone = GetComponent<VisionCone>();

        //Start the targetRot at current rot
        targetRot = transform.rotation;
    }
Beispiel #7
0
    // Start is called before the first frame update
    void Start()
    {
        timer        = new QuickTimer();
        pointers     = new List <Vector3>();
        maxIdleDelay = useOnlyMinIdle ? minIdleDelay : Random.Range(minIdleDelay, maxIdleDelay);
        m_nav        = gameObject.GetComponent <NavMeshAgent2D>();

        m_animator = gameObject.GetComponent <Animator>();

        //Initialize player reference
        var players = GameObject.FindGameObjectsWithTag("Player");

        if (players.Length > 1)
        {
            print("Error, more than one Player!");
        }
        else if (players.Length < 1)
        {
            print("Error, no Player!");
        }
        else
        {
            player = players[0];
        }

        //Initialize goals if necessary
        if (goals.Count == 0 || goals[0] == null)
        {
            var goalList = GameObject.FindGameObjectsWithTag("EnemyWaypoint");
            goals = new List <GameObject>(goalList);
        }

        alertSprite    = transform.Find("AlertSprite").gameObject;
        alert_animator = alertSprite.GetComponent <Animator>();

        vision = GetComponentInChildren <VisionCone>();
        vision.viewDistance = maxVisionDistance;
        vision.fov          = visionConeAngle * 2;

        Vector3 hearingCircleScale = transform.Find("VisionCircle").localScale;

        hearingCircleScale.x = 2f * maxHearingDistance;
        hearingCircleScale.y = 2f * maxHearingDistance;
        transform.Find("VisionCircle").localScale = hearingCircleScale;

        this.originalSpeed = m_nav.speed;
    }
Beispiel #8
0
    /// <summary>
    /// Draws the radius of size sightDistance around the agent.
    ///
    /// Adaptation of Lague, S. (2015) Field of view visualisation (E01). Available at: https://www.youtube.com/watch?v=rQG9aUWarwE (Accessed: 05 January 2018).
    /// </summary>
    private void OnSceneGUI()
    {
        VisionCone cone = (VisionCone)target; // Agent's FOV cone in game

        Handles.color = Color.white;          // Change colour to white


        // View distance
        Handles.DrawWireArc(cone.transform.position, Vector3.up, Vector3.forward, 360, cone.viewDistance); // Draw a circle of radius sightDistance around agent

        // View angle
        // Get the angle in radians of half the view angle left and right of the agent's forward vector.
        float rightSightAngle = ((cone.FOV / 2) + cone.transform.eulerAngles.y) * Mathf.Deg2Rad;
        float leftSightAngle  = ((cone.FOV / 2) - cone.transform.eulerAngles.y) * Mathf.Deg2Rad;

        // Convert these angles to direction vectors
        Vector3 rightSightPoint = new Vector3(Mathf.Sin(rightSightAngle), 0.0f, Mathf.Cos(rightSightAngle));
        Vector3 leftSightPoint  = new Vector3(Mathf.Sin(-leftSightAngle), 0.0f, Mathf.Cos(-leftSightAngle));

        // Draw a line from the agent's position, along the direction vectors until they intersect with the view distance.
        Handles.DrawLine(cone.transform.position, cone.transform.position + rightSightPoint * cone.viewDistance);
        Handles.DrawLine(cone.transform.position, cone.transform.position + leftSightPoint * cone.viewDistance);



        // Enemies in proximity
        List <GameObject> enemies        = cone.getNearbyTargets();
        List <GameObject> visibleEnemies = cone.getNearbyTargets();

        for (int i = 0; i < enemies.Count; i++)
        {
            if (!visibleEnemies.Contains(enemies[i])) // Can't see enemy
            {
                Handles.color = Color.red;
            }
            else
            {
                float percentageVisible = cone.getTimeVisible(enemies[i]) / cone.timeToSpot;
                Color visibilityColour  = new Color(1 - percentageVisible, percentageVisible, 0);

                Handles.color = visibilityColour;
            }

            Handles.DrawLine(cone.transform.position, enemies[i].transform.position);
        }
    }
    private void Awake()
    {
        player       = FindObjectOfType <BlinkScript>().gameObject;
        followPlayer = false;        // Empezar en modo "Passive"
        speed        = passiveSpeed; // Empezar a la velocidad de patrulla
        cadenceTimer = cadence;
        gun.rotation = Quaternion.identity;
        gfxAnimator  = GetComponentInChildren <Animator>();
        gfxAnimator.SetTrigger("Walk");


        // PATHFINDING
        seeker = GetComponent <Seeker>();
        rb     = GetComponent <Rigidbody2D>();

        fovVar          = fov;
        viewDistanceVar = viewDistance;

        // CONO VISION
        visionConeScript = Instantiate(visionConePrfb, visionConeGroup.transform).GetComponent <VisionCone>();
        visionConeScript.SetFov(fovVar);
        visionConeScript.SetViewDistance(viewDistanceVar);
    }
Beispiel #10
0
    // Update is called once per frame
    void Update()
    {
        Animator _animator = GetComponent <Animator>();

        VisionCone cone = GetComponentInChildren <VisionCone>();

        Transform shadow           = GameObject.FindWithTag("Shadow").transform;
        float     difference       = GameObject.FindWithTag("PlayerCharacter").transform.position.x - transform.position.x;
        float     switchDifference = CloseSwitch.transform.position.x - transform.position.x;

        if (cone.detectsPlayer) // if he sees the player, be alerted
        {
            if (alertTime == 0)
            {
                GetComponent <AudioSource>().Play();
            }
            alertTime = alertDuration;
            print("Found player");
            breaks = true;
        }
        if (cone.detectsShadow) // if he sees the shadow, be alerted differently
        {
            if (alertTime == 0)
            {
                GetComponent <AudioSource>().Play();
            }
            shadowTime = alertDuration;
            breaks     = true;
        }

        if (alertTime <= 0 && shadowTime <= 0)
        {
            if (breaks) // if unalerted but still moved over
            {
                float goOriginal = start.x - transform.position.x;

                if (goOriginal < -0.1f)
                {
                    transform.rotation = Quaternion.Euler(0, 0, 0);
                    moving             = true;
                    transform.Translate(Vector3.left * Time.deltaTime * speed / 2);
                }
                else if (goOriginal > 0.1f)
                {
                    transform.rotation = Quaternion.Euler(0, 180, 0);
                    moving             = true;
                    transform.Translate(Vector3.left * Time.deltaTime * speed / 2);
                }
                else
                {
                    breaks    = false;
                    moving    = false;
                    goingLeft = startsLeft;
                    paceTime  = paceLength / speed;
                } //go back to original spot and start pathing again
            }
            else
            {
                if (paceTime >= 0)
                {
                    paceTime -= Time.deltaTime;
                    moving    = true;
                    transform.Translate(Vector3.left * Time.deltaTime * speed / 2);
                } //pace left
                else if (paceTime < 0 && paceTime >= -pacePause)
                {
                    paceTime -= Time.deltaTime;
                    moving    = false;
                }
                else
                {
                    goingLeft = !goingLeft;
                    paceTime  = paceLength / speed;
                } //turn right

                if (goingLeft)
                {
                    transform.rotation = Quaternion.Euler(0, 0, 0);
                }
                else
                {
                    transform.rotation = Quaternion.Euler(0, 180, 0);
                }
            }

            GetComponentInChildren <AlertDisplay>().alerted = false;
        }
        else if (alertTime > 0)
        {
            if (difference >= 0.5)
            {
                transform.rotation = Quaternion.Euler(0, 180, 0);
                moving             = true;
                transform.Translate(Vector3.left * Time.deltaTime * speed);
            } // move to player if not close
            else if (difference <= -0.5)
            {
                transform.rotation = Quaternion.Euler(0, 0, 0);
                moving             = true;
                transform.Translate(Vector3.left * Time.deltaTime * speed);
            } // stop if close to player
            else
            {
                moving = false;
            }

            GetComponentInChildren <AlertDisplay>().alerted = true;
            alertTime -= Time.deltaTime;
        }
        else if (shadowTime > 0)
        {
            if (switchDifference >= 0)
            {
                transform.rotation = Quaternion.Euler(0, 180, 0);
            }
            else
            {
                transform.rotation = Quaternion.Euler(0, 0, 0);
            } // turn to switch

            if (CloseSwitch.GetComponent <LightSwitch>().on)
            {
                moving = true;
                transform.Translate(Vector3.left * Time.deltaTime * speed);
            }  // go to switch
            else
            {
                moving = false;
            }

            shadowTime -= Time.deltaTime;

            if (Mathf.Abs(switchDifference) < 1)
            {
                if (CloseSwitch.GetComponent <LightSwitch>().on&& shadowTime > 0)
                {
                    CloseSwitch.GetComponent <LightSwitch>().Turn();
                }
                else if (!CloseSwitch.GetComponent <LightSwitch>().on&& shadowTime <= 0)
                {
                    CloseSwitch.GetComponent <LightSwitch>().Turn();
                }
            } // turn off switch if close
            GetComponentInChildren <AlertDisplay>().alerted = true;
        }


        _animator.SetBool("Moving", moving);
    }
 private void Start()
 {
     player  = Player.instance;
     enemy   = GetComponent <Enemy>();
     visionC = GetComponentInChildren <VisionCone>();
 }
 // Use this for initialization
 void Start()
 {
     visionConeBehaviour = GetComponent <VisionCone>(); // Get vision cone attached to gameobject
 }