Beispiel #1
0
    private void CollisionSphereBox()
    {
        float3 spherePos    = posA;
        float3 obbPos       = posB;
        float3 obbRot       = rotB;
        float3 obbHalfSize  = extentsB;
        float  sphereRadius = extentsA.x;

        FixedList128 <float3> vertices = ColPhysics.GetAABBVerticesOBB(obbPos, obbHalfSize);   // calculated once at startup forever stored with entity

        vertices = ColPhysics.GetRotatedVerticesOBB(vertices, obbPos, obbRot);
        FixedList128 <float> extents = new FixedList128 <float>(); // calculated once at startup forever stored with entity

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

        FixedList128 <float3> axisNormals = ColPhysics.GetAxisNormalsOBB(vertices[0], vertices[1], vertices[3], vertices[4]);

        if (ColPhysics.SphereIntersectsBox(spherePos, sphereRadius, obbPos, axisNormals, extents, out float distance))
        {
            isColliding = true;

            if (resolveCollisions)
            {
                ColPhysics.ResolveSphereBoxCollision(ref spherePos, sphereRadius, ref obbPos, distance);
                posA = spherePos;
                posB = obbPos;
            }
        }
    }