Exemplo n.º 1
0
    private void CollisionCapsuleLock()
    {
        float3 p1 = posA;
        float3 p2 = posB;
        float  r1 = extentsA.x;
        float  r2 = extentsB.x;
        float  h1 = extentsA.y * 2;
        float  h2 = extentsB.y * 2;

        if (ColPhysics.ParallelLinesIntersectYAxis(p1.y, p2.y, h1, h2))
        {
            float3 s1 = new float3(p1.x, 0, p1.z);
            float3 s2 = new float3(p2.x, 0, p2.z);

            if (ColPhysics.SpheresIntersect(s1, s2, r1, r2, out float distance))
            {
                isColliding = true;

                if (resolveCollisions)
                {
                    ColPhysics.ResolveSphereCollision(ref s1, ref s2, r1, r2, distance);

                    posA = new float3(s1.x, p1.y, s1.z);
                    posB = new float3(s2.x, p2.y, s2.z);
                }
            }
        }
    }
Exemplo n.º 2
0
    private void CollisionSphere()
    {
        float3 pa = posA;
        float3 pb = posB;
        float  ra = extentsA.x;
        float  rb = extentsB.x;

        if (ColPhysics.SpheresIntersect(pa, pb, ra, rb, out float distance))
        {
            isColliding = true;

            if (resolveCollisions)
            {
                ColPhysics.ResolveSphereCollision(ref pa, ref pb, ra, rb, distance);

                posA = pa;
                posB = pb;
            }
        }
    }
Exemplo n.º 3
0
    private void CollisionCapsule()
    {
        float3 pa      = posA;
        float3 pb      = posB;
        float  lengthA = extentsA.y * 2;
        float  lengthB = extentsB.y * 2;
        float  radiusA = extentsA.x;
        float  radiusB = extentsB.x;

        if (ColPhysics.CapsuleIntersectsCapsule(pa, pb, rotA, rotB, lengthA, lengthB, radiusA, radiusB, out float distance))
        {
            isColliding = true;

            if (resolveCollisions)
            {
                ColPhysics.ResolveSphereCollision(ref pa, ref pb, radiusA, radiusB, distance);

                posA = pa;
                posB = pb;
            }
        }
    }
Exemplo n.º 4
0
    private void CollisionSphereCapsule()
    {
        float3 spherePos    = posA;
        float  sphereRadius = extentsA.x;

        float3 capsulePos    = posB;
        float3 capsuleRot    = rotB;
        float  capsuleLength = extentsB.y * 2;
        float  capsuleRadius = extentsB.x;

        if (ColPhysics.SphereIntersectsCapsule(spherePos, sphereRadius, capsulePos, capsuleRot, capsuleLength, capsuleRadius, out float distance))
        {
            isColliding = true;

            if (resolveCollisions)
            {
                ColPhysics.ResolveSphereCollision(ref spherePos, ref capsulePos, sphereRadius, capsuleRadius, distance);

                posA = spherePos;
                posB = capsulePos;
            }
        }
    }