Example #1
0
 public void basicAttack()
 {
     if (!cooldowns[0])
     {
         StartCoroutine(jab());
         int sound_determiner = Random.Range(0, 9);
         if (sound_determiner <= 4)
         {
             SoundManagerScript.PlaySound("ATK1");
         }
         else
         {
             SoundManagerScript.PlaySound("ATK2");
         }
         RaycastHit2D[] hits = Physics2D.BoxCastAll(wielder.position, Vector2.one, 0f, attackDir, 1f);
         ExtDebug.DrawBoxCast2D(wielder.position, Vector2.one, 0f, attackDir, 1f, Color.blue, 1f);
         foreach (RaycastHit2D hit in hits)
         {
             if (hit.transform.CompareTag("Enemy"))
             {
                 hit.transform.GetComponent <Enemy>().takeDamage(damage);
                 damage = 7;
             }
         }
         StartCoroutine(FadeTo(1f, cooldown, 0, cooldownImage));
     }
 }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        // angle += 45 * Time.deltaTime;



        float distance = 5.5f;

        //Angle Target to rotate box

        Quaternion angleAxis      = Quaternion.AngleAxis(-angle, Vector3.up);
        Vector3    angleDirection = transform.position + (transform.forward * distance);
        Vector3    angleTarget    = RotateAroundPoint(angleDirection, transform.position, angleAxis);


        //Projection of the box
        Vector3    origin      = transform.position;
        Vector3    halfExtents = Vector3.one / 2f;
        Vector3    direction   = angleTarget - origin;               //Transform.forward
        Quaternion orientation = Quaternion.LookRotation(direction); //Transform.rotation


        RaycastHit hitInfo;

        if (Physics.BoxCast(origin, halfExtents, direction, out hitInfo, orientation, distance))
        {
            ExtDebug.DrawBoxCastOnHit(origin, halfExtents, orientation, direction, hitInfo.distance, Color.red);
        }


        ExtDebug.DrawBoxCastBox(origin, halfExtents, orientation, direction, distance, Color.green);
    }
Example #3
0
    public bool IsHitForwad(float distance, out PlayerController hitPlayer, CampTeam team)
    {
        bool             result      = false;
        PlayerController hitedPlayer = null;

        Vector3    origem      = transform.position + (transform.forward * 1.0f);
        Vector3    halfExtents = Vector3.one / 2f;
        Vector3    direction   = transform.forward;
        Quaternion orientation = transform.rotation;

        RaycastHit hitInfo;

        if (Physics.BoxCast(origem, halfExtents, direction, out hitInfo, orientation, distance, LayerMask.GetMask("SoccerPlayer")))
        {
            if (hitInfo.transform.GetComponent <PlayerController>() != null)
            {
                hitedPlayer = hitInfo.transform.GetComponent <PlayerController>();

                if (hitedPlayer.GetCampTeam() == team && hitedPlayer.isOk)
                {
                    result = true;
                }

                ExtDebug.DrawBoxCastOnHit(origem, halfExtents, orientation, direction, hitInfo.distance, Color.red);
            }


            //ExtDebug.DrawBoxCastOnHit(origem, halfExtents, orientation, direction, hitInfo.distance, Color.red);
        }

        //ExtDebug.DrawBox(origem, halfExtents, orientation, Color.red);
        hitPlayer = hitedPlayer;
        return(result);
    }
Example #4
0
    private void CheckForInteractables()
    {
        Ray interactableRay = new Ray(transform.position, transform.forward);

        ExtDebug.DrawBoxCastBox(transform.position, boxcast_HalfExtends, transform.rotation, transform.forward, RAY_LENGTH, Color.red);

        RaycastHit hitPoint;

        if (Physics.BoxCast(transform.position, boxcast_HalfExtends, transform.forward, out hitPoint, transform.rotation, RAY_LENGTH, interactableMask))
        {
            if (hitPoint.transform.GetComponent <InteractableObject>() != null)
            {
                InteractableObject observedObject = hitPoint.transform.GetComponent <InteractableObject>();

                if (observedObject.IsLocked == false && HasAccessToInteract(observedObject))
                {
                    if (currentSelected == null)
                    {
                        Select(observedObject);
                    }
                    else if (currentSelected != observedObject)
                    {
                        DeSelect(currentSelected);
                        Select(observedObject);
                    }
                }
                return;
            }
        }

        if (currentSelected != null)
        {
            DeSelect(currentSelected);
        }
    }
Example #5
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        //If Character Hits the Bottom of the Mystery Box Spawn Item of Correct Type
        ExtDebug.DrawBoxCastBox(transform.position, bounds, Quaternion.identity, Vector2.down, boxCastCheckDistance, Color.white);
        if (Physics2D.BoxCast(transform.position, bounds, 0, Vector2.down, boxCastCheckDistance, Player))
        {
            if (collision.gameObject.CompareTag("Player") && boxActive)
            {
                switch (boxState)
                {
                case BoxState.coin:
                    SpawnItem(0);
                    break;

                case BoxState.mushroom:
                    SpawnItem(1);
                    break;

                case BoxState.fireFlower:
                    SpawnItem(2);
                    break;

                case BoxState.oneUp:
                    SpawnItem(3);
                    break;

                case BoxState.star:
                    SpawnItem(4);
                    break;
                }
            }
        }
    }
Example #6
0
    private void FixedUpdate()
    {
        Vector3 pos = this.transform.position + Vector3.up * coll.center.y;

        ExtDebug.DrawBoxCastOnHit(pos, coll.bounds.extents, this.transform.rotation, transform.forward, RaycastLength, Color.red);
        CheckIfPlayerIsNear();
    }
Example #7
0
    private bool CheckWorldCollisions(WorldChanger.WorldState worldState)
    {
        Vector3 colliderExtents = transform.lossyScale * .49f;

        //  Evaluate the world state that player is transferring to.
        switch (worldState)
        {
        //  cast present ray & evaluate
        case WorldChanger.WorldState.Present:
            Vector3 presentPos = new Vector3(transform.position.x, transform.position.y, 0);

            if (Application.isEditor)
            {
                ExtDebug.DrawBox(presentPos, colliderExtents, transform.rotation, Color.blue);
            }

            if (currentWorldState != WorldChanger.WorldState.Present && Physics.CheckBox(presentPos, colliderExtents, transform.rotation, Layers.Players))
            {
                //Debug.Log("Colliding present...");
                return(false);
            }
            break;

        //  cast past ray & evaluate
        case WorldChanger.WorldState.Past:
            Vector3 pastPos = new Vector3(transform.position.x, transform.position.y, 50);

            if (Application.isEditor)
            {
                ExtDebug.DrawBox(pastPos, colliderExtents, transform.rotation, Color.blue);
            }

            if (currentWorldState != WorldChanger.WorldState.Past && Physics.CheckBox(pastPos, colliderExtents, transform.rotation, Layers.Players))
            {
                //Debug.Log("Colliding past...");
                return(false);
            }
            break;

        //  cast future ray & evaluate
        case WorldChanger.WorldState.Future:
            Vector3 futurePos = new Vector3(transform.position.x, transform.position.y, 100);

            if (Application.isEditor)
            {
                ExtDebug.DrawBox(futurePos, colliderExtents, transform.rotation, Color.blue);
            }

            if (currentWorldState != WorldChanger.WorldState.Future && Physics.CheckBox(futurePos, colliderExtents, transform.rotation, Layers.Players))
            {
                //Debug.Log("Colliding future...");
                return(false);
            }
            break;
        }
        //Debug.Log("No Collide...");
        return(true);
    }
Example #8
0
    public void RotateForDiscover()
    {
        Quaternion tempR = Quaternion.LookRotation(transform.forward);

        tempR = tempR * Quaternion.Euler(0, RotateNumber, 0);
        Vector3 tempD = tempR * Vector3.forward;

        hits = Physics.BoxCastAll(gameObject.transform.position + new Vector3(0, 1, 0), new Vector3(EnemySight, EnemySight, 0), tempD, Quaternion.identity, VisibilityDistance);
        ExtDebug.DrawBox(gameObject.transform.position + new Vector3(0, 1, 0), new Vector3(EnemySight, EnemySight, 0), tempR, Color.yellow);
        StartCoroutine(ChangeNumberInTime(0.2f));
    }
Example #9
0
    //Check if a potential spot is too close to other objects
    public static int TooClose(Vector3 spot, GameObject mat, LayerMask lm)
    {
        //Quaternion ang = mat.transform.rotation;
        //ang = new Quaternion(ang.x, Random.Range(0, 360), ang.z, ang.w);
        Collider[] obstCheck = Physics.OverlapBox(spot, mat.GetComponent <BasicThrown>().size / 2, new Quaternion(), ~lm);

        //if (obstCheck.Length > 0)
        //    ang = new Quaternion();

        ExtDebug.DrawBox(spot, mat.GetComponent <BasicThrown>().size / 2, new Quaternion(), Color.red, 0.5f);
        return(obstCheck.Length);
    }
Example #10
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit haut;
        float      rcGoomba = 0.35f;
        //this.animator.Play("Agrandir");
        //AnimatorStateInfo state = anim.GetCurrentAnimatorStateInfo(0);
        //Debug.Log(this.animator.GetCurrentAnimatorStateInfo(0).ToString());
        //Debug.Log (this.animator.GetCurrentAnimatorStateInfo(0).IsName("Agrandir"));

        /*	if (this.animator.GetCurrentAnimatorStateInfo(0).IsName("Agrandir")  )
         * {
         *  Debug.Log("est en train de grandir");
         *              taille = 1f;
         *
         * }
         */
        /*
         * Debug.DrawRay ( transform.position + new Vector3(0f,taille,0f),transform.forward , Color.red);
         * if (Physics.Raycast (transform.position+ new Vector3(0f,taille,0f), transform.forward, out devant, rcGoomba)) {
         *      //Debug.Log("ici" );
         *      if (devant.transform.tag=="Player") {
         *
         *      //	Destroy (devant.transform.gameObject);
         *
         *      }
         * }
         * Debug.DrawRay (transform.position + new Vector3(0f,taille,0f), -transform.forward, Color.red);
         * if (Physics.Raycast (transform.position+ new Vector3(0f,taille,0f), -transform.forward, out derriere, rcGoomba)) {
         *
         *      if (derriere.transform.tag=="Player") {
         *
         *      //	Destroy (derriere.transform.gameObject);
         *
         *      }
         * }*/
        Vector3 newPos = new Vector3(transform.position.x, transform.localScale.y, transform.position.z);

        newPos.y = newPos.y * adjustextension;
        newPos   = newPos + new Vector3(0f, transform.position.y, 0f);     // adjustement de la boxcast
        ExtDebug.DrawBoxCastOnHit(newPos, new Vector3(longueurHaut, longueurHaut, longueurHaut), Quaternion.identity, transform.up, rcGoomba, Color.red);
        if (Physics.BoxCast(newPos, new Vector3(longueurHaut, longueurHaut, longueurHaut), transform.up, out haut, Quaternion.identity, rcGoomba))
        {
            Debug.Log("touche haut");
            if (haut.transform.tag == "Player")
            {
                haut.transform.GetComponent <mvt>().degat();
                Debug.Log("Le Mario Meurt");
                //Destroy(haut.transform.gameObject);
                //Destroy (derriere.transform.gameObject);
            }
        }
    }
    private void OnDrawGizmos()
    {
        Vector2 rightPos  = (Vector2)transform.position + new Vector2(xWidth + centerXOffset, -0.06f);
        Vector2 leftPos   = (Vector2)transform.position + new Vector2(-xWidth + centerXOffset, -0.06f);
        Vector2 bottomPos = (Vector2)transform.position + new Vector2(centerXOffset, yWidth + centerYOffset);

        ExtDebug.DrawBox(rightPos, new Vector2(rightWallDist / 2, rightWidth / 2), Quaternion.identity, Color.blue);
        ExtDebug.DrawBox(leftPos, new Vector2(leftWallDist / 2, leftWidth / 2), Quaternion.identity, Color.green);
        ExtDebug.DrawBox(bottomPos, new Vector2(bottomWidth / 2, floorDist / 2), Quaternion.identity, Color.cyan);

        //UnityEditor.Handles.Label((Vector2)transform.position + Vector2.up * 0.7f, OnAnyWall ? "On Wall" : "Not On Wall");
        //UnityEditor.Handles.Label((Vector2)transform.position - new Vector2(centerXOffset, centerYOffset), OnGround ? "On Ground" : "Not On Ground");
    }
Example #12
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     //Check if player collided with box and if player is not in small mario state destroy box
     ExtDebug.DrawBoxCastBox(transform.position, bounds, Quaternion.identity, Vector2.down, boxCastCheckDistance, Color.white);
     if (Physics2D.BoxCast(transform.position, bounds, 0, Vector2.down, boxCastCheckDistance, Player))
     {
         if (collision.gameObject.CompareTag("Player") &&
             characterController.characterState != CharacterController2Dimensional.CharacterState.smallMario)
         {
             Destroy(gameObject);
         }
     }
 }
    void InteractionRaycast()
    {
        Collider[] colls;

        Vector3 pos = this.transform.position + transform.forward * box.center.z;

        ExtDebug.DrawBox(pos + transform.forward * RaycastLength, BoxSize / 2, this.transform.rotation, Color.black);

        colls = Physics.OverlapBox(pos + transform.forward * RaycastLength, BoxSize / 2, this.transform.rotation, ~(1 << LayerMask.NameToLayer("Player")));

        if (colls.Length > 0) //Uhh this whole thing should run in O(n)? i think the way i set up the overlap box itself the max length <= 10? so shouldn't be too resource consuming
        {
            for (int i = 0; i < colls.Length; ++i)
            {
                if (colls[i].gameObject.GetComponent <Animal>() != null)
                {
                    PickupAnimal(colls[i].gameObject);
                    return;
                }
            }


            for (int i = 0; i < colls.Length; ++i)
            {
                if (colls[i].gameObject.GetComponent <Interactable>() != null)
                {
                    colls[i].gameObject.GetComponent <Interactable>().Interact();
                    return;
                }
            }


            for (int i = 0; i < colls.Length; ++i)
            {
                if (colls[i].gameObject.GetComponent <HeldObject>() != null)
                {
                    PickupObject(colls[i].gameObject);
                    return;
                }
            }

            for (int i = 0; i < colls.Length; ++i)
            {
                if (colls[i].gameObject.GetComponent <ResourceSource>() != null)
                {
                    CollectResource(colls[i].gameObject);
                    return;
                }
            }
        }
    }
Example #14
0
    bool ladderCheck()
    {
        RaycastHit2D[] rhit = new RaycastHit2D[256];

        int size = Physics2D.BoxCast(transform.position, bx2d.bounds.extents, 0, Vector2.zero, filter2D, rhit);

        ExtDebug.DrawBoxCastBox(transform.position, bx2d.bounds.extents, Quaternion.identity, Vector2.zero, Mathf.Infinity, Color.red);
        if (size == 0)
        {
            return(false);
        }

        return(true);
    }
Example #15
0
    private void DrawRayCasts()
    {
        for (int x = 0; x < Box.ScaleX; x++)
        {
            for (int z = 0; z < Box.ScaleZ; z++)
            {
                Vector3 rayOrigin = new Vector3(Box.Min.x + x, Box.Max.y, Box.Min.z + z);

                ExtDebug.DrawBoxCastBox(rayOrigin, new Vector3(0.5f, 0.5f, 0.5f), Quaternion.identity, Vector3.down,
                                        10f,
                                        Color.blue);
            }
        }
    }
Example #16
0
    private void FixedUpdate()
    {
        //+ new Vector3(rcLongueur, rcTaille, framelongueur)

        if (this.gameObject.tag.Equals("Champi"))
        {
            ExtDebug.DrawBoxCastOnHit(transform.position + new Vector3(rcLongueur, rcTaille + 0.5f, framelongueur), new Vector3(longueurHaut, longueurHaut, longueurHaut) / 2, Quaternion.identity, transform.up, 1.0f, Color.red);
            if (Physics.BoxCast(transform.position + new Vector3(rcLongueur, rcTaille + 0.5f, framelongueur), new Vector3(longueurHaut, longueurHaut, longueurHaut), transform.up, out triggerTete, Quaternion.identity, 1))
            {
                if (triggerTete.transform.tag.Equals("Player"))
                {
                    if (this.gameObject.tag.Equals("Champi"))
                    {
                        triggerTete.transform.GetComponent <Questionb>().MarioDevienGrand(true);
                    }

                    Destroy(this.gameObject);
                }
            }
        }

        if (this.gameObject.tag.Equals("piece"))
        {
            ExtDebug.DrawBoxCastOnHit(transform.position + new Vector3(0, 1, 0), new Vector3(longueurHaut, longueurHaut, longueurHaut) / 2, Quaternion.identity, transform.forward, 1.0f, Color.red);
            if (Physics.BoxCast(transform.position + new Vector3(0, 1, 0), new Vector3(longueurHaut, longueurHaut, longueurHaut), transform.forward, out triggerTete, Quaternion.identity, 1))
            {
                if (triggerTete.transform.tag.Equals("Player"))
                {
                    if (Global.isMulti)
                    {
                        if (triggerTete.transform.gameObject.GetComponent <mvt>().getIsMine())
                        {
                            Global.score++;
                            Debug.Log("Il s'agit d'une piece");
                        }
                    }
                    else
                    {
                        Global.score++;
                        Debug.Log("Il s'agit d'une piece2");
                    }
                    Destroy(this.gameObject);
                }
            }
        }
    }
Example #17
0
    bool RaycastForObstacle()
    {
        RaycastHit hit;

        Vector3 pos = this.transform.position + Vector3.up * coll.center.y;

        ExtDebug.DrawBoxCastOnHit(pos, coll.bounds.extents, this.transform.rotation, transform.forward, RaycastLength, Color.red);

        if (Physics.BoxCast(pos, coll.bounds.extents, transform.forward, out hit, this.transform.rotation, RaycastLength, ~(1 << LayerMask.NameToLayer("Animal"))))
        {
            if (hit.collider != null)
            {
                return(true);
            }
        }
        return(false);
    }
Example #18
0
    IEnumerator Attack()
    {
        Vector2 direction = player.position - transform.position;

        currDirection = direction;
        //Slime winds up.
        Debug.Log("Slime prepares to attack!");
        float elapsed_time = 0.0f;

        while (elapsed_time <= 1.0f)
        {
            elapsed_time += Time.deltaTime;
            yield return(null);
        }

        //Play SFX
        //FindObjectOfType<AudioManager>().Play("HitSFX");

        int attack_determiner = Random.Range(0, 9);

        if (attack_determiner <= .3)
        {
            Debug.Log("Slime attacks with spitball!");
            Instantiate(SpitBall, transform.position, Quaternion.identity);
        }
        else
        {
            Debug.Log("Slime attacks with headbutt!");
            //RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, hitRadius, Vector2.zero);
            Vector2        hitbox = new Vector2(0.5f, 0.5f);
            RaycastHit2D[] hits   = Physics2D.BoxCastAll((Vector2)transform.position, hitbox, 0f, currDirection, 1f);
            ExtDebug.DrawBoxCast2D((Vector2)transform.position, hitbox, 0f, currDirection, 1f, Color.red, 1f);

            foreach (RaycastHit2D hit in hits)
            {
                if (hit.transform.CompareTag("Player"))
                {
                    Debug.Log("Hit player with headbutt in direction " + currDirection);
                    hit.transform.GetComponent <playerTest>().takeDamage(damageDealt);
                }
            }
        }
        timeBetweenAttacks = 5.0f;
        attacking          = false;
    }
Example #19
0
    /*
     *
     *  switch (FacingDirection)
     *  {
     *      case Directions.backwards:
     *          ObjectInDirection.y = 0;
     *          break;
     *      case Directions.forward:
     *          ObjectInDirection.y = 0;
     *          break;
     *      case Directions.left:
     *          ObjectInDirection.x = 0;
     *          break;
     *      case Directions.right:
     *          ObjectInDirection.x = 0;
     *          break;
     *      case Directions.b_left: // (transform.right + transform.forward).normalized
     *          Debug.Log(FacingDirection.ToString());
     *          if (DirectionalRaycast((transform.right + transform.forward).normalized, Color.red))
     *          {
     *              HitObject = true;
     *              ObjectInDirection.x = 0;
     *              Debug.Log("Hit Horizontally");
     *          }
     *          if (DirectionalRaycast(((transform.right * -1) + transform.forward).normalized, Color.cyan))
     *          {
     *              HitObject = true;
     *              ObjectInDirection.y = 0;
     *              Debug.Log("Hit vertically");
     *          }
     *
     *          if (!HitObject)
     *          {
     *              if (DirectionalRaycast(transform.forward, Color.black))
     *              {
     *                  Debug.Log("Hit diagonally");
     *                  ObjectInDirection = Vector2.zero;
     *              }
     *          }
     *
     *          break;
     *      case Directions.b_right:
     *          Debug.Log(FacingDirection.ToString());
     *          if (DirectionalRaycast(((transform.right * -1) + transform.forward).normalized, Color.red))
     *          {
     *              HitObject = true;
     *              ObjectInDirection.x = 0;
     *              Debug.Log("Hit Horizontally");
     *          }
     *          if (DirectionalRaycast((transform.right + transform.forward).normalized, Color.cyan))
     *          {
     *              HitObject = true;
     *              ObjectInDirection.y = 0;
     *              Debug.Log("Hit vertically");
     *          }
     *
     *          if (!HitObject)
     *          {
     *              if (DirectionalRaycast(transform.forward, Color.black))
     *              {
     *                  Debug.Log("Hit diagonally");
     *                  ObjectInDirection = Vector2.zero;
     *              }
     *          }
     *
     *          break;
     *      case Directions.f_left:
     *          Debug.Log(FacingDirection.ToString());
     *          if (DirectionalRaycast(((transform.right * -1) + transform.forward).normalized, Color.red))
     *          {
     *              HitObject = true;
     *              ObjectInDirection.x = 0;
     *              Debug.Log("Hit Horizontally");
     *          }
     *          if (DirectionalRaycast((transform.right + transform.forward).normalized, Color.cyan))
     *          {
     *              HitObject = true;
     *              ObjectInDirection.y = 0;
     *              Debug.Log("Hit vertically");
     *          }
     *
     *          if (!HitObject)
     *          {
     *              if (DirectionalRaycast(transform.forward, Color.black))
     *              {
     *                  Debug.Log("Hit diagonally");
     *                  ObjectInDirection = Vector2.zero;
     *              }
     *          }
     *          break;
     *      case Directions.f_right:
     *          Debug.Log(FacingDirection.ToString());
     *          if (DirectionalRaycast((transform.right + transform.forward).normalized, Color.red))
     *          {
     *              HitObject = true;
     *              ObjectInDirection.x = 0;
     *              Debug.Log("Hit Horizontally");
     *          }
     *          if (DirectionalRaycast(((transform.right * -1) + transform.forward).normalized, Color.cyan))
     *          {
     *              HitObject = true;
     *              ObjectInDirection.y = 0;
     *              Debug.Log("Hit vertically");
     *          }
     *
     *          if (!HitObject)
     *          {
     *              if (DirectionalRaycast(transform.forward, Color.black))
     *              {
     *                  Debug.Log("Hit diagonally");
     *                  ObjectInDirection = Vector2.zero;
     *              }
     *          }
     *
     *          break;
     *  }
     */

    #endregion

    bool DirectionalRaycast(Vector3 dir, Color col, bool isDiagonal = false)
    {
        Collider[] colls;

        Vector3 pos       = GetPosToBoxCastFrom() + Vector3.down * 0.7f;
        Vector3 size      = (dir == Vector3.right || dir == Vector3.right * -1  ? new Vector3((isHoldingObject ? 0.8f : 0.6f), 0.1f, 0.1f) : new Vector3(0.1f, 0.1f, (isHoldingObject ? 0.8f : 0.6f)));
        float   longerRay = RaycastLength;

        ExtDebug.DrawBox(pos + dir * (isDiagonal ? Mathf.Sqrt(Mathf.Pow(longerRay, 2)) : longerRay), size, (isDiagonal ? this.transform.rotation : Quaternion.identity), col);

        colls = Physics.OverlapBox(pos + dir * (isHoldingObject ? 2f : 1f) * (isDiagonal ? Mathf.Sqrt(2 * Mathf.Pow(longerRay, 2)) : longerRay), size, Quaternion.identity, ~(1 << LayerMask.NameToLayer("Player")));

        if (colls.Length > 0)
        {
            return(true);
        }
        return(false);
    }
    public static RaycastWallHit GetWallHitBox(Vector3 origin, Vector3 direction, Vector3 extents, Quaternion orientation, float distance, bool debug = false)
    {
        RaycastHit hitInfo;

        if (debug)
        {
            ExtDebug.DrawBoxCastBox(origin, extents, orientation, direction, distance, Color.green);
        }

        if (Physics.BoxCast(origin, extents, direction, out hitInfo, orientation, distance, LayerMask.GetMask("Wall")))
        {
            Wall wall = hitInfo.transform.GetComponent <Wall> ();

            if (wall != null)
            {
                return(new RaycastWallHit(wall, hitInfo.normal, hitInfo.point));
            }
        }
        return(new RaycastWallHit());
    }
Example #21
0
    void CheckForObstruction()
    {
        Collider[] colls;

        ExtDebug.DrawBoxCastOnHit(this.transform.position, coll.bounds.extents * 1.3f, this.transform.rotation, transform.forward, 0, Color.red);

        colls = Physics.OverlapBox(this.transform.position, coll.bounds.extents * 1.3f, this.transform.rotation, ~(1 << this.gameObject.layer));


        if (colls.Length > 0)
        {
            this.audio.PlayOneShot(errorPlacement);
            CanPlace = false;
        }
        else
        {
            CanPlace = true;
        }
        //Debug.Log("Can Place: " + CanPlace);
    }
Example #22
0
		} // End Move



		override public System.Nullable<RaycastHit> Cast(Vector3 direction, float distance) {

			bool hit;
			RaycastHit hitInfo;

			hit = Physics.BoxCast(
				hitInfo:      out hitInfo,

				center:       transform.position,   halfExtents:             castBoxSize,
				direction:    direction,            layerMask:               collisionMask.constValue,
				orientation:  transform.rotation,   queryTriggerInteraction: QueryTriggerInteraction.Ignore,
				maxDistance:  distance
			);


			#if UNITY_EDITOR
			if(debugCasts.constValue) {
				ExtDebug.DrawBoxCastBox(
					origin:      transform.position, halfExtents: castBoxSize,
					orientation: transform.rotation, direction:   direction,
					distance:    distance,           

					duration:    debugCastLifetime,
					color:       (hit ? debugCastAttempt : debugCastMiss)
				);

				if(hit) {
					ExtDebug.DrawBoxCastOnHit(
						origin:          transform.position,      halfExtents:     castBoxSize,
						orientation:     transform.rotation,      direction:       direction,
						hitInfoDistance: hitInfo.distance,

						duration:        debugCastLifetime,
						color:           debugCastHit
					);
				}
			}
			#endif

			return new System.Nullable<RaycastHit>(hitInfo);
		} // End Cast
    //private void OnCollisionEnter(Collision collision)
    //{
    //    ContactPoint[] contacts = new ContactPoint[10];
    //    collision.GetContacts(contacts);

    //    foreach(var hit in contacts)
    //    {
    //        HandleParkour(collision, hit);
    //    }
    //}

    private void OnTriggerStay(Collider other)
    {
        if (!StartedRegJump)
        {
            var point = other.ClosestPoint(transform.position);

            ExtDebug.DrawBox(point, Vector3.one / 2, Quaternion.identity, Color.blue);

            var        dir = point - transform.position;
            RaycastHit hit;

            Debug.DrawLine(transform.position, point, Color.white);

            if (Physics.Raycast(transform.position, dir, out hit, wallDist, wallLayer, QueryTriggerInteraction.Ignore) && !playerController.Grounded)
            {
                Debug.DrawRay(point, hit.normal, Color.green);

                HandleParkour(other.gameObject, hit);
            }
        }
    }
Example #24
0
    bool isAtTop()
    {
        RaycastHit2D[] rhit          = new RaycastHit2D[256];
        Vector3        lowerPosition = transform.position;

        lowerPosition.x -= bx2d.size.y / 4;

        Vector3 smallBounds = bx2d.bounds.extents;

        smallBounds.y /= 2;

        int size = Physics2D.BoxCast(lowerPosition, smallBounds, 0, Vector2.zero, filter2D, rhit);

        ExtDebug.DrawBoxCastBox(lowerPosition, smallBounds, Quaternion.identity, Vector2.zero, Mathf.Infinity, Color.blue);
        if (size == 0)
        {
            return(false);
        }

        return(true);
    }
Example #25
0
    bool IsGrounded()
    {
        ContactFilter2D filter = new ContactFilter2D();

        filter.layerMask    = terrainLayerMask;
        filter.useLayerMask = true;

        Vector2 box = coll2d.bounds.extents;

        box -= new Vector2(0.02f, 0);

        Vector2 lowerDown = coll2d.bounds.center;

        lowerDown.y -= coll2d.bounds.size.y;

        RaycastHit2D[] rhits = new RaycastHit2D[256];

        int size = Physics2D.BoxCast(lowerDown, box, 0f, Vector2.zero, filter, rhits);

        ContactPoint2D[] point = new ContactPoint2D[256];

        int contSize = rb2d.GetContacts(point);

        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < contSize; j++)
            {
                if (point[j].collider == rhits[i].collider)
                {
                    //Debug.Log("Yes I am grounded!");
                    //Debug.Log(rhits[i].collider);
                    return(true);
                }
            }
        }

        ExtDebug.DrawBoxCastBox(lowerDown, box, Quaternion.identity, Vector2.zero, 0, Color.red);
        return(false);
    }
Example #26
0
		} // End Cast



		override public RaycastHit[] CastAll(Vector3 direction, float distance) {

			RaycastHit[] hitInfoAr;

			hitInfoAr = Physics.BoxCastAll(
				center:       transform.position,   halfExtents:             castBoxSize,
				direction:    direction,            layerMask:               collisionMask.constValue,
				orientation:  transform.rotation,   queryTriggerInteraction: QueryTriggerInteraction.Ignore,
				maxDistance:  distance
			);


			#if UNITY_EDITOR
			if(debugCasts.constValue) {
				ExtDebug.DrawBoxCastBox(
					origin:      transform.position, halfExtents: castBoxSize,
					orientation: transform.rotation, direction:   direction,
					distance:    distance,           

					duration:    debugCastLifetime,
					color:       (hitInfoAr.Length > 0 ? debugCastAttempt : debugCastMiss)
				);

				foreach(RaycastHit hitInfo in hitInfoAr) {
					ExtDebug.DrawBoxCastOnHit(
						origin:          transform.position,      halfExtents:     castBoxSize,
						orientation:     transform.rotation,      direction:       direction,
						hitInfoDistance: hitInfo.distance,

						duration:        debugCastLifetime,
						color:           debugCastHit
					);
				}
			}
			#endif

			return hitInfoAr;
		} // End CastAll
Example #27
0
    public bool IsPositionAheadClear(Vector2 movementDir, float lookAhead)
    {
        float sizeScale = .5f;
        int   layer     = gameObject.layer;

        gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");
        RaycastHit2D hit = Physics2D.BoxCast(transform.position, new Vector2(boxCollider.size.x * transform.localScale.x * sizeScale, boxCollider.size.y * transform.localScale.y * sizeScale), 0, movementDir, lookAhead, mask);

        //ExtDebug.DrawBoxCastBox(transform.position, new Vector2(boxCollider.size.x * transform.localScale.x * sizeScale, boxCollider.size.y * transform.localScale.y * sizeScale), Quaternion.identity, movementDir, lookAhead, Color.green, .1f);
        if (hit.collider != null)
        {
            gameObject.layer = layer;
            hitCollider      = hit.collider;
            Debug.DrawRay((Vector2)transform.position - (Vector2) new Vector2(boxCollider.size.x * transform.localScale.x * sizeScale, boxCollider.size.y * transform.localScale.y * sizeScale), 2 * new Vector2(boxCollider.size.x * transform.localScale.x * .9f, boxCollider.size.y * transform.localScale.y * .9f), Color.red, 1);
            //Debug.DrawLine(transform.position, hit.collider.gameObject.transform.position, Color.red, 1);
            ExtDebug.DrawBoxCastBox(transform.position, new Vector2(boxCollider.size.x * transform.localScale.x * sizeScale, boxCollider.size.y * transform.localScale.y * sizeScale), Quaternion.identity, movementDir, lookAhead, Color.red, 1);
            Debug.DrawLine(transform.position, hit.collider.gameObject.transform.position, Color.red, 1);
            return(false);
        }
        ExtDebug.DrawBoxCastBox(transform.position, new Vector2(boxCollider.size.x * transform.localScale.x * sizeScale, boxCollider.size.y * transform.localScale.y * sizeScale), Quaternion.identity, movementDir, lookAhead, Color.green, .1f);
        gameObject.layer = layer;
        return(true);
    }
Example #28
0
    private bool IsOpenForMove(Vector3 direction, float distance)
    {
        RaycastHit hitInfo;
        var        capsuleCollider = GetComponent <CapsuleCollider>();

        var boxDimensions = new Vector3(capsuleCollider.radius, capsuleCollider.height / 2 * 0.9f, capsuleCollider.radius);

        boxDimensions.Scale(transform.localScale);

        var hit = Physics.BoxCast(
            transform.position,
            boxDimensions,
            direction,
            out hitInfo,
            Quaternion.identity,
            distance,
            CastMask,
            QueryTriggerInteraction.Ignore);

        if (IsDebug)
        {
            if (hit)
            {
                hitInfo.collider.gameObject.GetComponent <Block>().AnimateBlocked();
            }

            ExtDebug.DrawBoxCastOnHit(
                transform.position,
                boxDimensions,
                Quaternion.identity,
                direction,
                distance,
                Color.blue);
        }

        return(!hit);
    }
Example #29
0
 void LateUpdate()
 {
     if (targetT != null && !buildingPlaced)
     {
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             Destroy(targetT.gameObject);
             buildingPlaced = true;
             targetT        = null;
             return;
         }
         else if (Input.GetKeyDown(KeyCode.Comma))
         {
             rot -= 90;
         }
         else if (Input.GetKeyDown(KeyCode.Period))
         {
             rot += 90;
         }
         targetT.position = new Vector3(((int)PointAndClick.TerrainMouseLocation.x), (int)PointAndClick.TerrainMouseLocation.y, ((int)PointAndClick.TerrainMouseLocation.z));
         targetT.rotation = Quaternion.Euler(90, rot, 0);
         ExtDebug.DrawBoxCastBox(new Vector3(targetT.position.x, targetT.position.y + 7, targetT.position.z), new Vector3(area.size.x / 2, 0.01f, area.size.y / 2), Quaternion.Euler(0, rot, 0), Vector3.down, 6.9f, new Color(0, 0, 1, 0.7f));
         if (Physics.BoxCast(new Vector3(targetT.position.x, targetT.position.y + 7, targetT.position.z), new Vector3(area.size.x / 2, 0.01f, area.size.y / 2), Vector3.down, Quaternion.Euler(0, rot, 0), 6.9f))
         {
             targetT.GetComponent <Renderer>().material.mainTexture = area.RedTex;
         }
         else
         {
             targetT.GetComponent <Renderer>().material.mainTexture = area.GreenTex;
             if (Input.GetMouseButtonDown(0))
             {
                 buildingPlaced = true;
             }
         }
     }
 }
Example #30
0
    void Crosshair()
    {
        Vector3 center = col.bounds.center;

        center.y += 1.0f;
        center.z += 4.0f;
        ExtDebug.DrawBoxCastBox(center, transform.localScale * 3f, transform.rotation, transform.forward * -1, 100f, Color.red);

        /*
         * if(m_HitDetect = Physics.BoxCast(col.bounds.center,transform.localScale * 3f, transform.forward * -1, out crossTrigger)){
         *      if(crossTrigger.collider.tag == "Meteor"){
         *              Vector3 crosshairScreen = Camera.main.WorldToScreenPoint(crosshair.transform.position);
         *              Vector3 meteorScreen = Camera.main.WorldToScreenPoint(crossTrigger.collider.transform.position);
         *              crosshairScreen.x = meteorScreen.x;
         *              crosshairScreen.y = meteorScreen.y;
         *              crosshair.transform.position = Vector3.Lerp(crosshair.transform.position, Camera.main.ScreenToWorldPoint(crosshairScreen),1.0f);
         *              autoaim = true;
         *
         *      }
         * } else {
         *      crosshair.transform.localPosition = Vector3.Lerp(crosshair.transform.localPosition,constCrossPos,1.0f);
         *      autoaim = false;
         * } */
    }