예제 #1
0
    // not automatically called by the Unity engine
    // that's where the Supervisor comes in
    public static void FixedUpdate()
    {
        foreach (RigidBodySpherical rgd in rigidBodies)
        {
            foreach (BallColliderSpherical ball in rgd.colls)
            {
                foreach (ColliderSpherical col in colliders)
                {
                    // an object shouldn't collide with itself
                    if (col is BallColliderSpherical b && rgd.colls.Contains(b))
                    {
                        continue;
                    }

                    Vector4 closestPoint;
                    if (col.ClosestPoint(ball.center, out closestPoint) <= ball.radius)
                    {
                        Vector4 skinPoint;
                        ball.ClosestPoint(closestPoint, out skinPoint);
                        rgd.trans.localToWorld = Rot4.StraightFromTo((R4)skinPoint, (R4)closestPoint) * rgd.trans.localToWorld;
                    }
                }
            }
        }
    }