Exemplo n.º 1
0
        protected override void OnPostSolve()
        {
            base.OnPostSolve();

            // Material already replaced in OnGraspBegin
            if (_contactMode != ContactMode.GRASPED)
            {
                if (_recievedVelocityUpdate)
                {
                    //If we recieved a velocity update, gravity must always be disabled because the
                    //velocity update accounts for gravity.
                    if (_rigidbody.useGravity)
                    {
                        _rigidbody.useGravity = false;
                    }
                }
                else
                {
                    //If we did not recieve a velocity update, we set the rigidbody's gravity status
                    //to match whatever the user has set.
                    if (_rigidbody.useGravity != _useGravity)
                    {
                        _rigidbody.useGravity = _useGravity;
                    }

                    //Only apply if non-zero to prevent waking up the body
                    if (_accumulatedLinearAcceleration != Vector3.zero)
                    {
                        _rigidbody.AddForce(_accumulatedLinearAcceleration, ForceMode.Acceleration);
                    }

                    if (_accumulatedAngularAcceleration != Vector3.zero)
                    {
                        _rigidbody.AddTorque(_accumulatedAngularAcceleration, ForceMode.Acceleration);
                    }
                }

                if (_recievedVelocityUpdate || _minHandDistance <= 0.0f)
                {
                    // Shapes in the contact graph of a hand do not bounce.
                    _materialReplacer.ReplaceMaterials();
                }
                else
                {
                    // Shapes in the contact graph of a hand do not bounce.
                    _materialReplacer.RevertMaterials();
                }
            }

            //Reset so we can accumulate for the next frame
            _accumulatedLinearAcceleration  = Vector3.zero;
            _accumulatedAngularAcceleration = Vector3.zero;
            _minHandDistance    = float.MaxValue;
            _notifiedOfTeleport = false;
        }
Exemplo n.º 2
0
        protected override void OnPostSolve()
        {
            base.OnPostSolve();

            // Material already replaced in OnGraspBegin
            if (_contactMode != ContactMode.GRASPED)
            {
                if (_recievedVelocityUpdate)
                {
                    //If we recieved a velocity update, gravity must always be disabled because the
                    //velocity update accounts for gravity.
                    if (_rigidbody.useGravity)
                    {
                        _rigidbody.useGravity = false;
                    }
                }
                else
                {
                    //If we did not recieve a velocity update, we set the rigidbody's gravity status
                    //to match whatever the user has set.
                    if (_rigidbody.useGravity != _useGravity)
                    {
                        _rigidbody.useGravity = _useGravity;
                    }
                }

                if (_recievedVelocityUpdate || _minHandDistance <= 0.0f)
                {
                    // Shapes in the contact graph of a hand do not bounce.
                    _materialReplacer.ReplaceMaterials();
                }
                else
                {
                    // Shapes in the contact graph of a hand do not bounce.
                    _materialReplacer.RevertMaterials();
                }
            }

            _minHandDistance    = float.MaxValue;
            _notifiedOfTeleport = false;
        }