0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

BoxColliderの各面をPlaneとして取得するスクリプト

Posted at

BoxColliderの各面のPlaneが欲しい時があるのですが直接取得する方法がわからないのでスクリプトを組みました。
UnityのBoxColliderの頂点を取得するスクリプト をPlaneにしたものです

GetBoxColliderPlanes
    public static Plane[] GetBoxColliderPlanes(BoxCollider Col)
    {
        Transform trs = Col.transform;
        Vector3 sc = trs.lossyScale;

        sc.x *= Col.size.x;
        sc.y *= Col.size.y;
        sc.z *= Col.size.z;

        sc *= 0.5f;

        Vector3 cp = trs.TransformPoint(Col.center);

        Vector3 vx = trs.right * sc.x;
        Vector3 vy = trs.up * sc.y;
        Vector3 vz = trs.forward * sc.z;

        Plane[] planes = new Plane[6];
        planes[0] = new Plane(trs.right, cp + vx);
        planes[1] = new Plane(-trs.right, cp - vx);
        planes[2] = new Plane(trs.up, cp + vy);
        planes[3] = new Plane(-trs.up, cp - vy);
        planes[4] = new Plane(trs.forward, cp + vz);
        planes[5] = new Plane(-trs.forward, cp - vz);

        return planes;

    }

親の回転、縮小に対応しています
BoxPlane.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?