Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        // This is going to get really hard. Check for player AND dead bodies
        // Behave differently when a body is spotted.

        //for(int i = 0; i < subjects.Count; ++i)
        //{
        Vector2 origin    = transform.position; // + rotator.FrontOffset();
        Vector2 direction = (Vector2)player.transform.position - origin;

        targetSighted = false;

        float angle = Vector2.Angle(rotator.FrontOffset(), direction);

        // If player is in cone of vision, and there is an uninterrupted view
        // Or, if player is touching
        if ((angle < peripheralVision && ClearShot(origin, direction)) ||
            GridMover.Touching(gameObject, player.gameObject))
        {
            //rotator.FacePoint(player.GetDiscretePosition());
            targetSighted = true;
            location      = player.GetDiscretePosition();
            // AutoMover should determine what to do with this information
            //mover.SetChasing(true);
        }

        /*if(Vector2.Distance(transform.position, player.transform.position) < 1.5f)
         * {
         *  targetSighted = true;
         *  location = player.GetDiscretePosition();
         *  rotator.FacePoint(player.GetDiscretePosition());
         *  mover.SetChasing(true);
         * }*/
        //}
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        Vector2 origin    = transform.position;// + rotator.FrontOffset();
        Vector2 direction = (Vector2)player.transform.position - origin;

        float angle = Vector2.Angle(rotator.FrontOffset(), direction);

        if (angle < peripheralVision)
        {
            RaycastHit2D hit = Physics2D.Raycast(origin, direction, sightDistance, mask);
            if (hit.collider != null && hit.collider.CompareTag("Player"))
            {
                mover.SetDestination(player.GetDiscretePosition(), true);
                mover.SetChasing(true);
            }
        }
    }
Exemplo n.º 3
0
    public void FireShot()
    {
        Vector2      direction = target.transform.position - transform.position;
        RaycastHit2D hit       = Physics2D.Raycast(transform.position, direction, 9, mask);
        float        angle     = Vector2.Angle(rotator.FrontOffset(), direction);

        if (hit.collider == null || !hit.collider.CompareTag("Player") || angle > peripheralVision)
        {
            return;
        }

        angle    += Random.Range(0, marginOfError) * (Random.Range(0, 2) == 0 ? 1 : -1);
        direction = Quaternion.AngleAxis(angle, Vector3.forward) * direction;

        hit = Physics2D.Raycast(transform.position, direction, 9, mask);

        if (hit.collider != null && Vector3.Distance(transform.position, target.transform.position) > 1)
        {
            source.PlayOneShot(gunshot);
            Camera.main.GetComponent <Jerk>().Shake(1);
            if (hit.collider.CompareTag("Player"))
            {
                //target.gameObject.GetComponent<ParticleSystem>().Play();
                target.gameObject.GetComponent <Flasher>().Flash(1);
                target.gameObject.GetComponent <Health>().TakeDamage();
            }
            GameObject shotObject = new GameObject();
            AutoVanish vanisher   = shotObject.AddComponent <AutoVanish>();
            vanisher.timeToLive = 0.05f;
            LineRenderer shotLine = shotObject.AddComponent <LineRenderer>();
            shotLine.SetPositions(new Vector3[] { transform.position + new Vector3(0, 0, -1), (Vector3)hit.point + new Vector3(0, 0, -1) });
            shotLine.sortingLayerName = "ForegroundFX";
            shotLine.material         = white;
            shotLine.startWidth       = shotLine.endWidth = 0.03f;
        }
    }