Exemplo n.º 1
0
    protected void RescaleMass()
    {
        // Rescale the mass back to the user value.
        float calculated = CP._cpBodyGetMass(_handle);

        CP.cpBodySetMass(_handle, _mass);

//		Debug.Log("Rescaling body mass. (mass: " + calculated + " moment: " + CP._cpBodyGetMoment(_handle) + ")");

        if (calculated > 0f && momentCalculationMode == ChipmunkBodyMomentMode.CalculateFromShapes)
        {
            float moment = CP._cpBodyGetMoment(_handle);
            this.moment = moment * _mass / calculated;
        }
        else if (momentCalculationMode == ChipmunkBodyMomentMode.Override)
        {
            this.moment = _customMoment;
        }
        else
        {
            this.moment = Mathf.Infinity;
        }

        // Cache the calculated moment.
        _customMoment = this.moment;
        if (_isKinematic)
        {
            CP.cpBodySetMass(_handle, Mathf.Infinity);
            CP.cpBodySetMoment(_handle, Mathf.Infinity);
        }

//		Debug.Log("Rescaled body mass. (mass: " + this.mass + " moment: " + this.moment + ")");
    }