コード例 #1
0
    private void CollisionCapsuleBox()
    {
        FixedList128 <float3> verticesOBB = ColPhysics.GetAABBVerticesOBB(posB, extentsB);

        verticesOBB = ColPhysics.GetRotatedVerticesOBB(verticesOBB, posB, rotB);
        FixedList128 <float3> normalAxesOBB = ColPhysics.GetAxisNormalsOBB(verticesOBB[0], verticesOBB[1], verticesOBB[3], verticesOBB[4]);
        FixedList128 <float>  exte          = new FixedList128 <float>();

        exte.Add(extentsB.x);
        exte.Add(extentsB.y);
        exte.Add(extentsB.z);

        float3x2 capsuleTips    = ColPhysics.GetCapsuleEndPoints(posA, rotA, extentsA.y * 2);
        float3x2 capsuleSpheres = ColPhysics.GetCapsuleEndSpheres(capsuleTips.c0, capsuleTips.c1, extentsA.x);

        if (ColPhysics.CapsuleIntersectsBox(capsuleSpheres, posB, extentsA.x, normalAxesOBB, exte, out float distance))
        {
            isColliding = true;

            if (resolveCollisions)
            {
                ColPhysics.ResolveSphereBoxCollision(ref posA, extentsA.x, ref posB, distance);
            }
        }
    }