Ejemplo n.º 1
0
    void CollideOnMove(ColliderResult result)
    {
        landColliders.Clear();

        transform.position = result.pos;
        Quaternion inverse    = Quaternion.Inverse(transform.rotation);
        Vector3    localSpeed = inverse * speed;

        foreach (RaycastHit2D hit in result.hits)
        {
            Vector3 localNormal = inverse * hit.normal;
            if (localNormal.y > 0.75f)
            {
                standAxis = new Vector2(hit.normal.x, hit.normal.y);
                OnFlags(Flag.Land);
                localSpeed.y = 0;

                landColliders.Add(hit.collider);
            }
            else if (localNormal.y < -0.5f)
            {
                localSpeed.y = Mathf.Min(localSpeed.y, 0);
            }
        }
        speed = transform.rotation * localSpeed;
    }
Ejemplo n.º 2
0
        public bool ThroughEnd(string colliderName)
        {
            ColliderResult target = results.Find(r => colliderName == r.otherCollider.colliderName);

            if (target == null)
            {
                return(false);
            }
            return(target.ThroughEnd());
        }
Ejemplo n.º 3
0
        public ColliderComponent GetOtherCollider(string colliderName)
        {
            ColliderResult target = results.Find(r => colliderName == r.otherCollider.colliderName);

            if (target == null)
            {
                return(null);
            }
            return(target.otherCollider);
        }
Ejemplo n.º 4
0
        public Entity GetOtherEntity(string colliderName)
        {
            ColliderResult target = results.Find(r => colliderName == r.otherCollider.colliderName);

            if (target == null)
            {
                return(null);
            }
            return(target.otherCollider.GetEntity());
        }
Ejemplo n.º 5
0
        public bool IsJostle(string colliderName)
        {
            ColliderResult target = results.Find(r => colliderName == r.otherCollider.colliderName);

            if (target == null)
            {
                return(false);
            }
            return(target.IsJostle());
        }
Ejemplo n.º 6
0
    // 衝突後の座標を算出する
    ColliderResult CalcCollidedPosition(
        Vector3 prevRootPos, Vector3 nextVec, int repeat = 1)
    {
        ColliderResult colliderResult = new ColliderResult();

        Debug.DrawRay(prevRootPos, nextVec, Color.yellow);

        Vector3 bodySize    = (GetComponent <Collider2D>() as BoxCollider2D).size;
        Vector3 prevBodyPos = prevRootPos + GetBodyOffset();
        Vector3 nextBodyPos = prevBodyPos + nextVec;

        for (int i = 0; i < repeat; ++i)
        {
            RaycastHit2D result = Physics2D.BoxCast(
                prevBodyPos, bodySize,
                transform.localEulerAngles.z,
                nextVec, nextVec.magnitude + 2,
                1 << LayerMask.NameToLayer("Default")
                );
            if (result.collider != null)
            {
                colliderResult.hits.Add(result);
                Vector3 bodyPos = nextBodyPos;

                Quaternion inverse     = Quaternion.Inverse(transform.rotation);
                Vector3    localNormal = inverse * result.normal;
                Vector3    localPoint  = inverse * result.point;
                nextBodyPos = inverse * nextBodyPos;

                if (Mathf.Abs(localNormal.x) > Mathf.Abs(localNormal.y))
                {
                    nextBodyPos.x = localPoint.x + (localNormal.x > 0 ? 1:-1) * (bodySize.x / 2 + 2);
                }
                else
                {
                    nextBodyPos.y = localPoint.y + (localNormal.y > 0 ? 1:-1) * (bodySize.y / 2 + 2);
                }

                nextBodyPos = transform.rotation * nextBodyPos;

                Debug.DrawLine(bodyPos, nextBodyPos, Color.gray);
                Debug.DrawLine(prevRootPos, result.point, Color.cyan);

                nextVec     = nextBodyPos - prevBodyPos;
                nextBodyPos = prevBodyPos + nextVec;
            }
            else
            {
                break;
            }
        }

        colliderResult.pos = nextBodyPos - GetBodyOffset();
        return(colliderResult);
    }
Ejemplo n.º 7
0
        protected void SetResultDataThrough(bool isThrough, ColliderComponent otherComp)
        {
            ColliderResult resultOther = results.Find(r => r.otherCollider == otherComp);

            if (resultOther == null)
            {
                if (isThrough)
                {
                    resultOther = new ColliderResult();
                    resultOther.otherCollider    = otherComp;
                    resultOther.isThroughCurrent = isThrough;
                    results.Add(resultOther);
                }
            }
            else
            {
                resultOther.isThroughCurrent = isThrough;
            }

            ColliderResult resultThis = otherComp.results.Find(r => r.otherCollider == this);

            if (resultThis == null)
            {
                if (isThrough)
                {
                    resultThis = new ColliderResult();
                    resultThis.otherCollider    = this;
                    resultThis.isThroughCurrent = true;
                    otherComp.results.Add(resultThis);
                }
            }
            else
            {
                resultThis.isThroughCurrent = isThrough;
            }
        }