Exemplo n.º 1
0
        public void StopManipulation()
        {
            if (m_state != MyState.NONE && Owner != null)
            {
                var characterMovementState = Owner.GetCurrentMovementState();
                switch (characterMovementState)
                {
                case MyCharacterMovementEnum.Walking:
                case MyCharacterMovementEnum.BackWalking:
                case MyCharacterMovementEnum.WalkingLeftFront:
                case MyCharacterMovementEnum.WalkingRightFront:
                case MyCharacterMovementEnum.WalkingLeftBack:
                case MyCharacterMovementEnum.WalkingRightBack:
                case MyCharacterMovementEnum.WalkStrafingLeft:
                case MyCharacterMovementEnum.WalkStrafingRight:
                case MyCharacterMovementEnum.Running:
                case MyCharacterMovementEnum.Backrunning:
                case MyCharacterMovementEnum.RunStrafingLeft:
                case MyCharacterMovementEnum.RunStrafingRight:
                case MyCharacterMovementEnum.RunningRightFront:
                case MyCharacterMovementEnum.RunningRightBack:
                case MyCharacterMovementEnum.RunningLeftFront:
                case MyCharacterMovementEnum.RunningLeftBack:
                    Owner.PlayCharacterAnimation("WalkBack", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f, 1f);
                    break;

                case MyCharacterMovementEnum.Standing:
                case MyCharacterMovementEnum.RotatingLeft:
                case MyCharacterMovementEnum.RotatingRight:
                case MyCharacterMovementEnum.Flying:
                    Owner.PlayCharacterAnimation("Idle", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f, 1f);
                    break;
                }
            }


            if (m_constraint != null)
            {
                if (OwnerVirtualPhysics != null)
                {
                    OwnerVirtualPhysics.RemoveConstraint(m_constraint);
                }

                m_constraint.Dispose();
                m_constraint = null;
            }

            if (m_fixedConstraintData != null)
            {
                if (!m_fixedConstraintData.IsDisposed)
                {
                    m_fixedConstraintData.Dispose();
                }

                m_fixedConstraintData = null;
            }

            m_headLocalPivotMatrix  = Matrix.Zero;
            m_otherLocalPivotMatrix = Matrix.Zero;
            if (m_otherEntity != null)
            {
                SetTransparent(m_otherEntity);

                if (m_state == MyState.HOLD)
                {
                    SetMotionOnClient(m_otherEntity, HkMotionType.Dynamic);

                    // Do not send when disconnecting
                    if (IsOwnerLocalPlayer() && !MyEntities.CloseAllowed && !(m_otherEntity is MyCharacter))
                    {
                        Sync.Players.RemoveControlledEntity(m_otherEntity);
                    }
                }

                m_manipulatedEntitites.Remove(m_otherEntity);
                var handler = ManipulationStopped;
                if (handler != null)
                {
                    handler(m_otherEntity);
                }

                m_otherEntity.SyncFlag = true;

                if (m_otherEntity.Physics != null && m_otherRigidBody != null && !m_otherRigidBody.IsDisposed)
                {
                    SetManipulated(m_otherEntity, false);
                    //m_otherRigidBody.AngularDamping = m_otherAngularDamping;
                    //m_otherRigidBody.LinearDamping = m_otherLinearDamping;
                    if (m_otherEntity is MyCharacter)
                    {
                        m_otherEntity.Physics.SetRagdollDefaults();
                    }
                    else
                    {
                        m_otherRigidBody.Restitution        = m_otherRestitution;
                        m_otherRigidBody.MaxLinearVelocity  = m_otherMaxLinearVelocity;
                        m_otherRigidBody.MaxAngularVelocity = m_otherMaxAngularVelocity;
                        if (m_massChange != null)
                        {
                            m_massChange.Remove();
                        }
                        m_massChange = null;
                        // Clamp output velocity
                        m_otherRigidBody.LinearVelocity  = Vector3.Clamp(m_otherRigidBody.LinearVelocity, -2 * Vector3.One, 2 * Vector3.One);
                        m_otherRigidBody.AngularVelocity = Vector3.Clamp(m_otherRigidBody.AngularVelocity, -Vector3.One * (float)Math.PI, Vector3.One * (float)Math.PI);
                        if (!m_otherRigidBody.IsActive)
                        {
                            m_otherRigidBody.Activate();
                        }
                        m_otherRigidBody.EnableDeactivation = false;
                        m_otherRigidBody.EnableDeactivation = true; //resets deactivation counter
                    }
                    m_otherRigidBody = null;
                }

                m_otherEntity.OnClosing -= OtherEntity_OnClosing;
                m_otherEntity            = null;
            }

            m_constraintInitialized = false;

            RemoveOwnerVirtualPhysics();

            if (Owner != null)
            {
                Owner.ManipulatedEntity = null;
            }
            m_state = MyState.NONE;
        }