// Awake
    void Awake()
    {
        base.Init();

        // Calculate the percentage difference to scale the colliders
        Vector2 percentageDifference = Vector2.zero;

        percentageDifference.x = transform.localScale.x / 1.0f;
        percentageDifference.y = transform.localScale.y / 1.0f;
        // Multiply ranges with scale
        // Platform detecting
        detectPlayerRange *= percentageDifference.x;
        // Charging
        chargingRange *= percentageDifference.x;
        // After Charging
        randWalkTimer = randWalkTime;
        // roaring
        roaringRange *= percentageDifference.x;
        // Shooting
        maxShootingRange *= percentageDifference.x;
        timeToHitTarget   = 1 / timeToHitTarget;
        // Melee
        meleeAttackRange *= percentageDifference.x;


        // Set up the contact filter
        contactFilter.SetLayerMask(LayerMask.GetMask("Player"));
        contactFilter.ClearDepth();
    }
Esempio n. 2
0
 public override void Initialize(SceneObjectManager newManager)
 {
     base.Initialize(newManager);
     sizes         = new Vector3[] { new Vector3(sizeRange.x, sizeRange.x, sizeRange.x), new Vector3(sizeRange.y, sizeRange.y, sizeRange.y) };
     contactFilter = new ContactFilter2D();
     contactFilter.SetLayerMask(LayerMask.GetMask("Buildings", "Asteroids"));
     contactFilter.ClearDepth();
 }
    void revive()
    {
        close();

        //gets player
        ControllerPlayer player = GameObject.FindGameObjectWithTag("Player").GetComponent <ControllerPlayer>();

        //heals player
        player.heal(10f);

        //kills all enemies in a 3 unit radius
        //creates layer mask
        LayerMask mask = 1 << 9;

        //creates filter
        ContactFilter2D filter = new ContactFilter2D();

        filter.SetLayerMask(mask);
        filter.ClearDepth();
        filter.useTriggers = true;

        //creates array
        Collider2D[] colliders = new Collider2D[30];

        //puts into array all the overlapping colliders
        Physics2D.OverlapCircle(player.transform.position, 3f, filter, colliders);

        //adds colliders into list
        foreach (Collider2D collide in colliders)
        {
            //tests if the collider is null
            if (collide == null)
            {
                continue;
            }

            //tests if the collider is a trigger
            if (collide.isTrigger)
            {
                continue;
            }

            //tests if the collider is a hitbox by checking if it is a box2d
            if (collide is BoxCollider2D)
            {
                EnemyMovement enemy = collide.gameObject.GetComponent <EnemyMovement>();
                if (enemy != null)
                {
                    enemy.damage(1f);
                }
            }
        }

        //revive Animation
        player.reviveAni();

        wasPreviouslyRevived = true;
    }
Esempio n. 4
0
        private int Perform2DOverlapPoint(Vector2 point, Collider2D[] results, LayerMask layerMask)
        {
            ContactFilter2D filter = new ContactFilter2D();

            filter.useTriggers = true;
            filter.SetLayerMask(layerMask);
            filter.ClearDepth();

            return(Physics2D.OverlapPoint(point, filter, results));
        }
        /**
         * <summary>Performs a Physics2D.Raycast on Triggers in the scene.</summary>
         * <param name = "origin">The ray's origin</param>
         * <param name = "direction">The ray's direction</param>
         * <param name = "length">The ray's length</param>
         * <returns>The result of the Physics2D.Raycast</returns>
         */
        public static RaycastHit2D Perform2DRaycast(Vector2 origin, Vector2 direction, float length)
        {
            RaycastHit2D[]  hits   = new RaycastHit2D [1];
            ContactFilter2D filter = new ContactFilter2D();

            filter.useTriggers = true;
            filter.ClearDepth();
            Physics2D.Raycast(origin, direction, filter, hits, length);
            return(hits[0]);
        }
Esempio n. 6
0
        /**
         * <summary>Performs a Physics2D.OverlapCircle on Triggers in the scene.</summary>
         * <param name = "point">The position of the circle's centre</param>
         * <param name = "radius">The radius of the circle</param>
         * <param name = "results">An array of results</param>
         * <param name = "layerMask">The LayerMask to act upon</param>
         * <returns>The result of the Physics2D.OverlapCircle</returns>
         */
        public static int Perform2DOverlapCircle(Vector2 point, float radius, Collider2D[] results, LayerMask layerMask)
        {
                        #if UNITY_5_6 || UNITY_5_6_OR_NEWER
            ContactFilter2D filter = new ContactFilter2D();
            filter.useTriggers = true;
            filter.SetLayerMask(layerMask);
            filter.ClearDepth();

            return(Physics2D.OverlapCircle(point, radius, filter, results));
                        #else
            return(Physics2D.OverlapCircleNonAlloc(point, radius, results, layerMask));
                        #endif
        }
Esempio n. 7
0
 /**
  * <summary>Performs a Physics2D.Raycast on Triggers in the scene.</summary>
  * <param name = "origin">The ray's origin</param>
  * <param name = "direction">The ray's direction</param>
  * <param name = "length">The ray's length</param>
  * <returns>The result of the Physics2D.Raycast</returns>
  */
 public static RaycastHit2D Perform2DRaycast(Vector2 origin, Vector2 direction, float length)
 {
                 #if UNITY_5_6 || UNITY_5_6_OR_NEWER
     RaycastHit2D[]  hits   = new RaycastHit2D [1];
     ContactFilter2D filter = new ContactFilter2D();
     filter.useTriggers = true;
     filter.ClearDepth();
     Physics2D.Raycast(origin, direction, filter, hits, length);
     return(hits[0]);
                 #else
     return(Physics2D.Raycast(origin, direction, length));
                 #endif
 }
    //returns an array of all enemies in range
    EnemyMovement[] getEnemiesInArea(Collider2D area)
    {
        //creates layer mask to include only attackables
        LayerMask mask = 1 << 9;

        //creates filter
        //ignores depth, includes mask, includes triggers
        ContactFilter2D filter = new ContactFilter2D();

        filter.ClearDepth();
        filter.SetLayerMask(mask);
        filter.useTriggers = true;

        //creates array
        Collider2D[] colliders = new Collider2D[50];

        //puts into array all the overlapping colliders
        Physics2D.OverlapCollider(area, filter, colliders);

        //creates temp list for collider
        List <EnemyMovement> list = new List <EnemyMovement> ();

        //adds colliders into list
        foreach (Collider2D collide in colliders)
        {
            //tests if the collider is null
            if (collide == null)
            {
                continue;
            }

            //tests if the collider is a trigger
            if (collide.isTrigger)
            {
                continue;
            }

            //tests if the collider is a hitbox by checking if it is a box2d
            if (collide is BoxCollider2D)
            {
                //adds to list
                list.Add(collide.gameObject.GetComponent <EnemyMovement> ());
            }
        }

        //returns list as array
        return(list.ToArray());
    }
Esempio n. 9
0
    // Start is called before the first frame update
    void Start()
    {
        currentState = STATES.S_EGG_DIFFERENTHEIGHT;

        // Convert int to floats for easier calculation
        timeToHitTarget = 1 / timeToHitTarget;
        // Set the Flee Timer
        fleeTimer = fleeTime;

        // Set the jumping Filters
        jumpingFilter.SetLayerMask(LayerMask.GetMask("JumpPointLayer"));
        jumpingFilter.ClearDepth();
        jumpingFilter.useTriggers = true;
        // Set the player Filters
        playerFilter.SetLayerMask(LayerMask.GetMask("Player"));
        playerFilter.ClearDepth();
        // Set the Platform Filters
        platformFilter.SetLayerMask(LayerMask.GetMask("Ground"));
        platformFilter.ClearDepth();

        // Calculate the percentage difference to scale the colliders
        Vector2 percentageDifference = Vector2.zero;

        percentageDifference.x = transform.localScale.x / 1.0f;
        percentageDifference.y = transform.localScale.y / 1.0f;
        // Multiply ranges with scale
        // Platform detecting
        sideTopDetect.detectOffset *= percentageDifference;
        sideTopDetect.detectSize   *= percentageDifference;
        bottomDetect.detectOffset  *= percentageDifference;
        bottomDetect.detectSize    *= percentageDifference;
        // Player detect
        playerDetectionRange *= percentageDifference.x;
        // Shooting
        maxShootingRange *= percentageDifference.x;
        // Melee
        meleeDistance *= percentageDifference.x;
    }