Esempio n. 1
0
    static public void CopyRigidbody2D(Rigidbody2D originalRigidBody, Slicer2D slicer, Polygon2D id, double originArea)
    {
        if (originalRigidBody)
        {
            Rigidbody2D newRigidBody = slicer.GetRigibody();

            newRigidBody.isKinematic            = originalRigidBody.isKinematic;
            newRigidBody.velocity               = originalRigidBody.velocity;
            newRigidBody.drag                   = originalRigidBody.drag;
            newRigidBody.angularVelocity        = originalRigidBody.angularVelocity;
            newRigidBody.angularDrag            = originalRigidBody.angularDrag;
            newRigidBody.constraints            = originalRigidBody.constraints;
            newRigidBody.gravityScale           = originalRigidBody.gravityScale;
            newRigidBody.collisionDetectionMode = originalRigidBody.collisionDetectionMode;
            newRigidBody.sharedMaterial         = originalRigidBody.sharedMaterial;
            //newRigidBody.sleepMode = originalRigidBody.sleepMode;
            //newRigidBody.inertia = originalRigidBody.inertia;

            // Center of Mass : Auto / Center
            if (slicer.centerOfMass == Slicer2D.CenterOfMass.RigidbodyOnly)
            {
                newRigidBody.centerOfMass = Vector2.zero;
            }

            if (slicer.recalculateMass)
            {
                float newArea = (float)id.ToLocalSpace(slicer.transform).GetArea();
                newRigidBody.mass = originalRigidBody.mass * (float)(newArea / originArea);
            }
            else
            {
                newRigidBody.mass = originalRigidBody.mass;
            }
        }
    }