public void OnTriggerEnter(Collider col)
    {
        if (!TimeLayer.EqualTimeLayer(col.gameObject, gameObject))
        {
            return;
        }

        if (col.gameObject.layer == LayerMask.NameToLayer("NPC"))
        {
            if (!nearNpcList.Contains(col))
            {
                nearNpcList.Add(col);
            }
        }
        else if (col.gameObject.layer == LayerMask.NameToLayer("Object"))
        {
            if (!nearObjList.Contains(col))
            {
                nearObjList.Add(col);
            }
        }
        else if (col.gameObject.layer == LayerMask.NameToLayer("Enemy"))
        {
            if (!nearEneList.Contains(col))
            {
                nearEneList.Add(col);
            }
        }
    }
Example #2
0
    void DescendSlope(ref Vector3 velocity)
    {
        float      directionX = Mathf.Sign(velocity.x);
        Vector3    rayOrigin  = (directionX == -1) ? raycastOrigins.bottomRight : raycastOrigins.bottomLeft;
        RaycastHit hit;

        if (Physics.Raycast(rayOrigin, -Vector3.up, out hit, Mathf.Infinity, collisionMask))
        {
            float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);
            if (slopeAngle != 0 && slopeAngle <= maxDescendAngle)
            {
                if (Mathf.Sign(hit.normal.x) == directionX)
                {
                    if (hit.distance - skinWidth <= Mathf.Tan(slopeAngle * Mathf.Deg2Rad) * Mathf.Abs(velocity.x))
                    {
                        if (TimeLayer.EqualTimeLayer(pTimeLayer, hit.collider.transform.GetComponentInParent <TimeLayer>()))
                        {
                            float moveDistance     = Mathf.Abs(velocity.x);
                            float descendVelocityY = Mathf.Sin(slopeAngle * Mathf.Deg2Rad) * moveDistance;
                            velocity.x  = Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * moveDistance * Mathf.Sign(velocity.x);
                            velocity.y -= descendVelocityY;

                            collisions.slopeAngle      = slopeAngle;
                            collisions.descendingSlope = true;
                            collisions.below           = true;
                        }
                    }
                }
            }
        }
    }
Example #3
0
    public void AlertToNearEnemy(float alertRadius, LayerMask alertMask)
    {
        Debug.Log("Alert");
        var colliders = Physics.OverlapSphere(transform.position, alertRadius, alertMask);

        for (int i = 0; i < colliders.Length; i++)
        {
            var escr = colliders[i].GetComponent <EnemyScript>();

            RaycastHit hit;
            Physics.Raycast(transform.position, (escr.transform.position - transform.position).normalized, out hit, alertRadius, alertMask);

            if (null != escr && escr != this)
            {
                if (TimeLayer.EqualTimeLayer(escr.pTimeLayer, pTimeLayer))
                {
                    if (!escr.GetSpecifiedState <DetectionState>(State.Detection).isDetection)
                    {
                        var targetPos = transform.position;
                        targetPos.y = escr.transform.position.y;
                        escr.GetSpecifiedState <SuspiciousState>(State.Suspicious).InitSuspiciousInfo(
                            Vector3.Lerp(escr.transform.position, targetPos, 0.9f)
                            , escr.moveSpeed * 1.0f);
                        escr.AddStateToListWithCheckingOverlap(escr.GetStateLayerKey(State.Suspicious));
                    }
                }
            }
        }
    }
Example #4
0
    public void CheckAndAddGrabCornerState()
    {
        if (isAir && !isClimb)
        {
            var cols = Physics.OverlapBox(transform.position, new Vector3(0.20f, 0.35f, 0.1f), Quaternion.identity, grabableLayer);
            for (int i = 0; i < cols.Length; i++)
            {
                var c = cols [i];
                if (!c.tag.Contains("Grabable"))
                {
                    continue;
                }

                if (TimeLayer.EqualTimeLayer(pTimeLayer, c.transform.GetComponentInParent <TimeLayer>()))
                {
                    if (pBoxCollider.bounds.min.y < c.bounds.max.y &&
                        pBoxCollider.bounds.max.y >= c.bounds.max.y - 0.1f)
                    {
                        if (Mathf.Sign(c.transform.position.x - transform.position.x) == Mathf.Sign(transform.localScale.x))
                        {
                            grappingObj = c;
                            AddToStateQueueWithCheckingOverlap(GetStatePriorityLevel(State.GrabCorner));
                        }
                    }
                }
            }
        }
    }
Example #5
0
    protected void VerticalCollisions()
    {
        float directionY = Mathf.Sign(velocity.y);
        float rayLength  = Mathf.Abs(velocity.y * Time.deltaTime);

        RaycastHit[][] browseHits = new RaycastHit[browseDensity][];

        maxX = GetComponent <Collider>().bounds.max.x;
        maxY = GetComponent <Collider>().bounds.max.y;
        minX = GetComponent <Collider>().bounds.min.x;
        minY = GetComponent <Collider>().bounds.min.y;

        for (int i = 0; i < browseDensity; i++)
        {
            var rayOrigin = new Vector3(minX + colXLen * (i / (browseDensity - 1)), ((velocity.y >= 0) ? maxY : minY), transform.position.z);
            Debug.DrawLine(rayOrigin, rayOrigin + Vector3.up * rayLength * directionY, Color.red);
            browseHits[i] = Physics.RaycastAll(rayOrigin, Vector3.up * directionY, rayLength, browseMask);

            for (int j = 0; j < browseHits[i].Length; j++)
            {
                // Debug.Log(browseHits[i][j].collider.name);
                if (browseHits[i][j].collider != null)
                {
                    if (TimeLayer.EqualTimeLayer(pTimeLayer, browseHits[i][j].transform.GetComponentInParent <TimeLayer>()) ||
                        browseHits[i][j].transform.CompareTag("Ground") ||
                        browseHits[i][j].transform.CompareTag("GrabableGround"))
                    {
                        velocity.y = 0;
                    }
                }
            }
        }
    }
Example #6
0
 private void ProcessTimeEffect()
 {
     if (TimeLayer.EqualTimeLayer(playerObject.ParentTimeLayer, pTimeLayer))
     {
         ((SecurityAnim)anim).PresentColor();
         skeletonGhost.ghostingEnabled = false;
     }
     else
     {
         ((SecurityAnim)anim).PastColor();
         skeletonGhost.ghostingEnabled = true;
     }
 }
Example #7
0
    private void EnemyLostPlayerByDifferentTimeLayer()
    {
        if (!TimeLayer.EqualTimeLayer(playerObject.ParentTimeLayer.gameObject, pTimeLayer.gameObject))
        {
            if (!isAttack)
            {
                DeleteStateToList(GetStateLayerKey(State.Attack));
                DeleteStateToList(GetStateLayerKey(State.Detection));
                GetSpecifiedState <DetectionState>(State.Detection).isDetection = false;

                detectionDurationTimer = 0;
            }
        }
    }
Example #8
0
 private void ProcessEnterStair(Collider col)
 {
     if (col.CompareTag("Stair"))
     {
         if (Input.GetKeyDown(KeyCode.W) &&
             !isWalkOnStair &&
             TimeLayer.EqualTimeLayer(pTimeLayer, col.GetComponentInParent <TimeLayer>()))
         {
             EnterStair(col);
             stairColliders = col.transform.parent.GetComponentsInChildren <BoxCollider>();
             InitStairZone();
         }
     }
 }
Example #9
0
 public bool CheckCollideable(RaycastHit tmpHit)
 {
     if (pTimeLayer == null)
     {
         return(false);
     }
     if ((TimeLayer.EqualTimeLayer(pTimeLayer, tmpHit.transform.GetComponentInParent <TimeLayer>()) ||
          tmpHit.transform.CompareTag("Ground") ||
          tmpHit.transform.CompareTag("GrabableGround")) &&
         tmpHit.transform != transform &&
         !tmpHit.collider.isTrigger)
     {
         return(true);
     }
     return(false);
 }
Example #10
0
 bool IsVerticalCollision()
 {
     for (int i = 0; i < 3; i++)
     {
         var hits = Physics.RaycastAll(Vector3.up * pBoxCollider.bounds.max.y + Vector3.right * pBoxCollider.bounds.min.x * (i / 2), Vector2.up, (INIT_COLLIDER_SIZE.y - SIT_COLLIDER_SIZE.y), controller.collisionMask);
         for (int j = 0; j < hits.Length; j++)
         {
             var hit = hits[j];
             if (hit.collider != null &&
                 TimeLayer.EqualTimeLayer(hit.collider.GetComponentInParent <TimeLayer>(), pTimeLayer))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #11
0
    public void Alert()
    {
        var colliders = Physics2D.OverlapCircleAll(enemyObj.transform.position, alertRadius, 1 << LayerMask.NameToLayer("Enemy"));

        for (int i = 0; i < colliders.Length; i++)
        {
            var col = colliders [i];
            if (TimeLayer.EqualTimeLayer(col.transform.GetComponentInParent <TimeLayer>(), enemyScript.pTimeLayer))
            {
                Debug.Log("Alert Ready");
                var hit = Physics2D.Raycast(enemyObj.transform.position + Vector3.up * 0.35f, (col.transform.position - enemyObj.transform.position).normalized, Vector2.Distance(col.transform.position, enemyObj.transform.position), 1 << LayerMask.NameToLayer("Collision"));

                if (hit.collider == null)
                {
                    col.GetComponent <EnemyScript> ().GetSpecifiedState <SuspiciousState> (State.Suspicious).InitSuspiciousInfo(enemyScript.GetSpecifiedState <SuspiciousState> (State.Suspicious).targetPos, col.GetComponent <EnemyScript> ().moveSpeed * 0.5f);
                    col.GetComponent <EnemyScript> ().SetState(State.Suspicious);
                }
            }
        }
    }
Example #12
0
    public Collider FindOutNearestCollider(Collider[] cols)
    {
        float           minDis   = 0;
        int             minIndex = 0;
        List <Collider> colList  = new List <Collider>();

        for (int i = 0; i < cols.Length; i++)
        {
            if (TimeLayer.EqualTimeLayer(cols[i].transform.GetComponentInParent <TimeLayer>(), pTimeLayer) ||
                cols[i].transform.CompareTag("Ground") || cols[i].transform.CompareTag("GrabableGround"))
            {
                colList.Add(cols[i]);
            }
        }

        if (colList.Count == 0)
        {
            return(null);
        }
        else if (colList.Count == 1)
        {
            return(colList[0]);
        }
        // 충돌체가 여러 개 라면
        else
        {
            minDis   = Vector2.Distance(colList[0].transform.position, transform.position);
            minIndex = 0;

            for (int i = 1; i < colList.Count; i++)
            {
                if (Vector2.Distance(colList[i].transform.position, transform.position) <= minDis)
                {
                    minDis   = Vector2.Distance(colList[i].transform.position, transform.position);
                    minIndex = i;
                }
            }
            return(colList[minIndex]);
        }
    }
Example #13
0
    //만약 탐지 가능한 객체(EqualTimeLayer == true)가 있으면 !null 요소가 만약 객체가 없으면 null
    public BrowseInfo[] Browse(float rayLen)
    {
        gBrowseHits = new RaycastHit[browseDensity][];
        BrowseInfo[] bInfos = new BrowseInfo[0];

        maxX = GetComponent <Collider>().bounds.max.x;
        maxY = GetComponent <Collider>().bounds.max.y;
        minX = GetComponent <Collider>().bounds.min.x;
        minY = GetComponent <Collider>().bounds.min.y;

        for (int i = 0; i < browseDensity; i++)
        {
            if (transform.localScale.x > 0)
            {
                gBrowseHits[i] = Physics.RaycastAll(
                    new Vector3(minX - 0.1f, maxY - colYLen * (i / (browseDensity - 1)), transform.position.z),
                    Vector3.right, rayLen + colXLen, browseMask);
            }
            else
            {
                gBrowseHits[i] = Physics.RaycastAll(
                    new Vector3(maxX + 0.1f, maxY - colYLen * (i / (browseDensity - 1)), transform.position.z),
                    Vector3.left, rayLen + colXLen, browseMask);
            }

            bInfos = new BrowseInfo[gBrowseHits[i].Length];

            for (int j = 0; j < gBrowseHits[i].Length; j++)
            {
                if (gBrowseHits[i][j].collider != null)
                {
                    if (TimeLayer.EqualTimeLayer(pTimeLayer, gBrowseHits[i][j].transform.GetComponentInParent <TimeLayer>()))
                    {
                        bInfos[j].InitBrowseInfo(gBrowseHits[i][j].collider.gameObject, gBrowseHits[i][j].distance, gBrowseHits[i][j].normal, gBrowseHits[i][j].point, gBrowseHits[i][j].transform.tag, gBrowseHits[i][j].transform.gameObject.layer);
                    }
                }
            }
        }
        return(bInfos);
    }
Example #14
0
 public float GetDistanceToGround()
 {
     for (int i = 0; i < 3; i++)
     {
         var origin = Vector3.up * pBoxCollider.bounds.min.y + Vector3.right * pBoxCollider.bounds.min.x + Vector3.right * pBoxCollider.size.x * (i / 2);
         Debug.DrawLine(Vector3.up * pBoxCollider.bounds.min.y + Vector3.right * pBoxCollider.bounds.min.x + Vector3.right * pBoxCollider.size.x * (i / 2),
                        Vector3.up * pBoxCollider.bounds.min.y + Vector3.right * pBoxCollider.bounds.min.x + Vector3.right * pBoxCollider.size.x * (i / 2) + Vector3.down * 3,
                        Color.red);
         var hits = Physics.RaycastAll(origin, Vector2.down, 3, controller.collisionMask);
         for (int j = 0; j < hits.Length; j++)
         {
             var hit = hits[j];
             if (hit.collider != null &&
                 TimeLayer.EqualTimeLayer(hit.collider.GetComponentInParent <TimeLayer>(), pTimeLayer) ||
                 hit.collider.tag.Contains("Ground"))
             {
                 return(hit.distance);
             }
         }
     }
     return(-1);
 }
Example #15
0
 public bool IsFindPlayer(float rayLen)
 {
     Browse(rayLen);
     for (int i = 0; i < browseDensity; i++)
     {
         for (int j = 0; j < gBrowseHits[i].Length; j++)
         {
             if (TimeLayer.EqualTimeLayer(pTimeLayer, gBrowseHits[i][j].collider.GetComponentInParent <TimeLayer>()))
             {
                 if (gBrowseHits[i][j].collider.gameObject.layer == LayerMask.NameToLayer("Collision"))
                 {
                     break;
                 }
                 else if (gBrowseHits[i][j].collider.gameObject.layer == LayerMask.NameToLayer("Player"))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Example #16
0
    void VerticalCollisions(ref Vector3 velocity)
    {
        float directionY = Mathf.Sign(velocity.y);
        float rayLength  = Mathf.Abs(velocity.y) + skinWidth;

        RaycastHit[][] browseHits = new RaycastHit[verticalRayCount][];

        for (int i = 0; i < verticalRayCount; i++)
        {
            Vector3 rayOrigin = (directionY == -1) ? raycastOrigins.bottomLeft:raycastOrigins.topLeft;
            rayOrigin    += Vector3.right * (verticalRaySpacing * i + velocity.x);
            browseHits[i] = Physics.RaycastAll(rayOrigin, Vector3.up * directionY, rayLength, collisionMask);

            for (int j = 0; j < browseHits[i].Length; j++)
            {
                var hit = browseHits [i] [j].collider;
                if (hit != null)
                {
                    if (TimeLayer.EqualTimeLayer(hit.GetComponentInParent <TimeLayer> (), pTimeLayer) ||
                        hit.CompareTag("Ground") || hit.CompareTag("GrabableGround") ||
                        hit.CompareTag("Bound") || hit.CompareTag("Stair") ||
                        hit.CompareTag("PassableCollision"))
                    {
                        if (hit.CompareTag("PassableCollision") && velocity.y > 0 && (GetComponent <Player> ().isJump))
                        {
                            break;
                        }

                        velocity.y = (browseHits [i] [j].distance - skinWidth) * directionY;
                        rayLength  = browseHits [i] [j].distance;

                        if (collisions.climbingSlope)
                        {
                            velocity.x = velocity.y / Mathf.Tan(collisions.slopeAngle * Mathf.Deg2Rad) * Mathf.Sign(velocity.x);
                        }
                        collisions.below = directionY == -1;
                        collisions.above = directionY == 1;
                    }
                }
            }
        }

        if (collisions.climbingSlope)
        {
            float directionX = Mathf.Sign(velocity.x);
            rayLength = Mathf.Abs(velocity.x) + skinWidth;
            Vector3    rayOrigin = ((directionX == -1)?raycastOrigins.bottomLeft:raycastOrigins.bottomRight) + Vector3.up * velocity.y;
            RaycastHit hit;

            if (Physics.Raycast(rayOrigin, Vector3.right * directionX, out hit, rayLength, collisionMask))
            {
                if (TimeLayer.EqualTimeLayer(hit.collider.transform.GetComponentInParent <TimeLayer>(), pTimeLayer) ||
                    hit.collider.CompareTag("Ground") ||
                    hit.collider.CompareTag("Bound") || hit.collider.CompareTag("Stair") ||
                    hit.collider.CompareTag("GrabbableGround")
                    )
                {
                    if (isWalkOnStair)
                    {
                        float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);
                        if (slopeAngle != collisions.slopeAngle)
                        {
                            velocity.x            = (hit.distance - skinWidth) * directionX;
                            collisions.slopeAngle = slopeAngle;
                        }
                    }
                }
            }
        }
    }
Example #17
0
 private bool IsCutsomEventTrigger(Collider col)
 {
     return(null != col.GetComponent <CustomEventTrigger> () && TimeLayer.EqualTimeLayer(gameObject, col.gameObject));
 }
Example #18
0
    void HorizontalCollisions(ref Vector3 velocity)
    {
        float directionX = Mathf.Sign(velocity.x);
        float rayLength  = Mathf.Abs(velocity.x) + skinWidth;

        for (int i = 0; i < horizontalRayCount; i++)
        {
            Vector3 rayOrigin = (directionX == -1) ? raycastOrigins.bottomLeft : raycastOrigins.bottomRight;
            rayOrigin += Vector3.up * (horizontalRaySpacing * i);
            RaycastHit hit;

            if (Physics.Raycast(rayOrigin, Vector3.right * directionX, out hit, rayLength, collisionMask))
            {
                float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);

                if (i == 0 && slopeAngle <= maxClimbAngle)
                {
                    if (TimeLayer.EqualTimeLayer(pTimeLayer, hit.collider.transform.GetComponentInParent <TimeLayer> ()) ||
                        hit.collider.CompareTag("Ground") || hit.collider.CompareTag("GrabableGround") ||
                        hit.collider.CompareTag("Bound") || hit.collider.CompareTag("Stair"))
                    {
                        float distanceToSlopeStart = 0;

                        ClimbSlope(ref velocity, slopeAngle);

                        if (collisions.descendingSlope)
                        {
                            collisions.descendingSlope = false;
                            velocity = collisions.velocityOld;
                        }
                        if (slopeAngle != collisions.slopeAngleOld)
                        {
                            distanceToSlopeStart = hit.distance - skinWidth;
                            velocity.x          -= distanceToSlopeStart * directionX;
                        }
                        velocity.x += distanceToSlopeStart * directionX;
                    }
                }

                if (!collisions.climbingSlope || slopeAngle > maxClimbAngle)
                {
                    if (TimeLayer.EqualTimeLayer(pTimeLayer, hit.collider.transform.GetComponentInParent <TimeLayer> ()) ||
                        hit.collider.CompareTag("Ground") || hit.collider.CompareTag("GrabableGround") ||
                        hit.collider.CompareTag("Bound") || hit.collider.CompareTag("Stair") ||
                        hit.collider.CompareTag("PassableCollision"))
                    {
                        velocity.x       = (hit.distance - skinWidth) * directionX;
                        collisions.left  = directionX == -1;
                        collisions.right = directionX == 1;

                        rayLength = hit.distance;

                        if (collisions.climbingSlope && isWalkOnStair)
                        {
                            velocity.y = Mathf.Tan(collisions.slopeAngle * Mathf.Deg2Rad) * Mathf.Abs(velocity.x);
                        }
                    }
                }
            }
        }
    }