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;
            }
        }
    }