Beispiel #1
0
        // @TODO: 外部のクラスに移譲する
        private void resolveCollision(Collision collision)
        {
            Bounds?intersection = ActionSampleCollision.GetIntersection(
                GetComponent <Collider>().bounds,
                collision.collider.bounds
                );

            if (intersection == null)
            {
                return;
            }

            ActionSampleCollision.DIMENSION?dimension = ActionSampleCollision.GetDimensionFromIntersection(
                GetComponent <Collider>().bounds,
                intersection ?? new Bounds()
                );

            float adjustX = 0;
            float adjustZ = 0;

            if (dimension == ActionSampleCollision.DIMENSION.LEFT)
            {
                adjustX = intersection?.size.x ?? 0;
            }
            if (dimension == ActionSampleCollision.DIMENSION.RIGHT)
            {
                adjustX = -intersection?.size.x ?? 0;
            }
            if (dimension == ActionSampleCollision.DIMENSION.FRONT)
            {
                adjustZ = intersection?.size.z ?? 0;
            }
            if (dimension == ActionSampleCollision.DIMENSION.REAR)
            {
                adjustZ = -intersection?.size.z ?? 0;
            }
            this.transform.Translate(new Vector3(adjustX, 0, adjustZ));
        }
Beispiel #2
0
        // @TODO: 判定と位置調整の処理は外部のサービスクラスに切り出す
        private void checkGrounded(Collision collision)
        {
            Bounds?intersection = ActionSampleCollision.GetIntersection(
                GetComponent <Collider>().bounds,
                collision.collider.bounds
                );

            if (intersection == null)
            {
                return;
            }

            ActionSampleCollision.DIMENSION?dimension = ActionSampleCollision.GetDimensionFromIntersection(
                GetComponent <Collider>().bounds,
                intersection ?? new Bounds()
                );
            if (dimension != ActionSampleCollision.DIMENSION.BOTTOM)
            {
                return;
            }
            this.groundCollider = collision.collider;
            this.transform.Translate(new Vector3(0, intersection?.size.y ?? 0, 0));
        }