public void Dispose()
        {
            if (CharacterProxy != null)
            {
                CharacterProxy.Dispose();
                CharacterProxy = null;
            }

            if (CharacterPhantom != null)
            {
                CharacterPhantom.Dispose();
                CharacterPhantom = null;
            }

            if (CharacterRigidBody != null)
            {
                if (CharacterRigidBody.GetRigidBody() != null)
                {
                    CharacterRigidBody.GetRigidBody().ContactPointCallback -= RigidBody_ContactPointCallback;
                }
                CharacterRigidBody.Dispose();
                CharacterRigidBody = null;
            }

            m_characterShape.RemoveReference();
            m_characterCollisionShape.RemoveReference();
            m_crouchShape.RemoveReference();
        }
Пример #2
0
 public void Activate(HkWorld world)
 {
     if (CharacterPhantom != null)
     {
         world.AddPhantom(CharacterPhantom);
     }
     if (CharacterRigidBody != null)
     {
         world.AddCharacterRigidBody(CharacterRigidBody);
         if (!float.IsInfinity(m_maxImpulse))
         {
             world.BreakOffPartsUtil.MarkEntityBreakable(CharacterRigidBody.GetRigidBody(), m_maxImpulse);
         }
     }
 }
Пример #3
0
        public MyCharacterProxy(bool isDynamic, bool isCapsule, float characterWidth, float characterHeight,
                                float crouchHeight, float ladderHeight, float headSize, float headHeight,
                                Vector3 position, Vector3 up, Vector3 forward,
                                float mass, MyPhysicsBody body, bool isOnlyVertical, float maxSlope, float maxImpulse, float maxSpeedRelativeToShip, float?maxForce = null, HkRagdoll ragDoll = null)
        {
            m_isDynamic              = isDynamic;
            m_physicsBody            = body;
            m_mass                   = mass;
            m_maxImpulse             = maxImpulse;
            m_maxSpeedRelativeToShip = maxSpeedRelativeToShip;

            if (isCapsule)
            {
                m_characterShape          = CreateCharacterShape(characterHeight, characterWidth, characterHeight + headHeight, headSize, 0, 0);
                m_characterCollisionShape = CreateCharacterShape(characterHeight * 0.9f, characterWidth * 0.9f, characterHeight * 0.9f + headHeight, headSize * 0.9f, 0, 0);
                m_crouchShape             = CreateCharacterShape(characterHeight, characterWidth, characterHeight + headHeight, headSize, 0.0f, 1.0f);

                if (!m_isDynamic)
                {
                    CharacterPhantom = new HkSimpleShapePhantom(m_characterShape, MyPhysics.CollisionLayers.CharacterCollisionLayer);
                }
            }
            else
            {
                HkBoxShape box = new HkBoxShape(new Vector3(characterWidth / 2.0f, characterHeight / 2.0f, characterWidth / 2.0f));
                if (!m_isDynamic)
                {
                    CharacterPhantom = new HkSimpleShapePhantom((HkShape)box, MyPhysics.CollisionLayers.CharacterCollisionLayer);
                }
                m_characterShape = box;
            }

            if (!m_isDynamic)
            {
                HkCharacterProxyCinfo characterProxyInfo = new HkCharacterProxyCinfo();
                characterProxyInfo.StaticFriction          = 1;
                characterProxyInfo.DynamicFriction         = 1;
                characterProxyInfo.ExtraDownStaticFriction = 1000;
                //characterProxyInfo.ContactAngleSensitivity = 20;
                //characterProxyInfo.KeepContactTolerance = 1f;
                characterProxyInfo.MaxCharacterSpeedForSolver    = 10000;
                characterProxyInfo.RefreshManifoldInCheckSupport = true;
                characterProxyInfo.Up                = up;
                characterProxyInfo.Forward           = forward;
                characterProxyInfo.UserPlanes        = 4;
                characterProxyInfo.MaxSlope          = MathHelper.ToRadians(maxSlope);
                characterProxyInfo.Position          = position;
                characterProxyInfo.CharacterMass     = mass;
                characterProxyInfo.CharacterStrength = 100;
                characterProxyInfo.ShapePhantom      = CharacterPhantom;

                CharacterProxy = new HkCharacterProxy(characterProxyInfo);

                characterProxyInfo.Dispose();
            }
            else
            {
                HkCharacterRigidBodyCinfo characterRBCInfo = new HkCharacterRigidBodyCinfo();
                characterRBCInfo.Shape               = m_characterShape;
                characterRBCInfo.CrouchShape         = m_crouchShape;
                characterRBCInfo.Friction            = 0;
                characterRBCInfo.MaxSlope            = MathHelper.ToRadians(maxSlope);
                characterRBCInfo.Up                  = up;
                characterRBCInfo.Mass                = mass;
                characterRBCInfo.CollisionFilterInfo = MyPhysics.CollisionLayers.CharacterCollisionLayer;
                //characterRBCInfo.UnweldingHeightOffsetFactor = 100;
                characterRBCInfo.MaxLinearVelocity       = 1000000;
                characterRBCInfo.MaxForce                = maxForce.HasValue ? maxForce.Value : 100000;
                characterRBCInfo.AllowedPenetrationDepth = MyFakes.ENABLE_LIMITED_CHARACTER_BODY ? 0.3f : 0.1f;
                characterRBCInfo.JumpHeight              = 0.8f;

                bool  shouldLimitSpeed  = Sync.IsServer;
                float maxCharacterSpeed = shouldLimitSpeed ? (MyGridPhysics.ShipMaxLinearVelocity() + m_maxSpeedRelativeToShip) : MyGridPhysics.MAX_SHIP_SPEED;
                CharacterRigidBody = new HkCharacterRigidBody(characterRBCInfo, maxCharacterSpeed, body, isOnlyVertical);

                CharacterRigidBody.GetRigidBody().ContactPointCallbackEnabled = true;
                CharacterRigidBody.GetRigidBody().ContactPointCallback       += RigidBody_ContactPointCallback;
                CharacterRigidBody.GetRigidBody().ContactPointCallbackDelay   = 0;

                //CharacterRigidBody.GetHitRigidBody().ContactPointCallbackEnabled = true;
                //CharacterRigidBody.GetHitRigidBody().ContactPointCallback += RigidBody_ContactPointCallback;
                //CharacterRigidBody.GetHitRigidBody().ContactPointCallbackDelay = 0;

                //CharacterRigidBody.SetSupportDistance(10);
                //CharacterRigidBody.SetHardSupportDistance(10);

                characterRBCInfo.Dispose();
            }
        }
Пример #4
0
        public MyCharacterProxy(bool isDynamic, bool isCapsule, float characterWidth, float characterHeight,
            float crouchHeight, float ladderHeight, float headSize, float headHeight,
            Vector3 position, Vector3 up, Vector3 forward,
            float mass, MyPhysicsBody body, bool isOnlyVertical, float maxSlope, float maxImpulse, HkRagdoll ragDoll = null)
        {
            m_isDynamic = isDynamic;
            m_physicsBody = body;
            m_mass =  mass;
            m_maxImpulse = maxImpulse;

            if (isCapsule)
            {
                m_characterShape = CreateCharacterShape(characterHeight, characterWidth, characterHeight + headHeight, headSize, 0, 0);
                m_characterCollisionShape = CreateCharacterShape(characterHeight * 0.9f, characterWidth * 0.9f, characterHeight * 0.9f + headHeight, headSize * 0.9f, 0, 0);
                m_crouchShape = CreateCharacterShape(characterHeight, characterWidth, characterHeight + headHeight, headSize, 0.0f, 1.0f);

                if (!m_isDynamic)
                    CharacterPhantom = new HkSimpleShapePhantom(m_characterShape, MyPhysics.CharacterCollisionLayer);
            }
            else
            {
                HkBoxShape box = new HkBoxShape(new Vector3(characterWidth / 2.0f, characterHeight / 2.0f, characterWidth / 2.0f));
                if (!m_isDynamic)
                    CharacterPhantom = new HkSimpleShapePhantom((HkShape)box, MyPhysics.CharacterCollisionLayer);
                m_characterShape = box;
            }

            if (!m_isDynamic)
            {
                HkCharacterProxyCinfo characterProxyInfo = new HkCharacterProxyCinfo();
                characterProxyInfo.StaticFriction = 1;
                characterProxyInfo.DynamicFriction = 1;
                characterProxyInfo.ExtraDownStaticFriction = 1000;
                //characterProxyInfo.ContactAngleSensitivity = 20;
                //characterProxyInfo.KeepContactTolerance = 1f;
                characterProxyInfo.MaxCharacterSpeedForSolver = 10000;
                characterProxyInfo.RefreshManifoldInCheckSupport = true;
                characterProxyInfo.Up = up;
                characterProxyInfo.Forward = forward;
                characterProxyInfo.UserPlanes = 4;
                characterProxyInfo.MaxSlope = MathHelper.ToRadians(maxSlope);
                characterProxyInfo.Position = position;
                characterProxyInfo.CharacterMass = mass;
                characterProxyInfo.CharacterStrength = 100;
                characterProxyInfo.ShapePhantom = CharacterPhantom;

                CharacterProxy = new HkCharacterProxy(characterProxyInfo);

                characterProxyInfo.Dispose();          
            }
            else
            {
                HkCharacterRigidBodyCinfo characterRBCInfo = new HkCharacterRigidBodyCinfo();
                characterRBCInfo.Shape = m_characterShape;
                characterRBCInfo.CrouchShape = m_crouchShape;
                characterRBCInfo.Friction = 0;
                characterRBCInfo.MaxSlope = MathHelper.ToRadians(maxSlope);
                characterRBCInfo.Up = up;
                characterRBCInfo.Mass = mass;
                characterRBCInfo.CollisionFilterInfo = MyPhysics.CharacterCollisionLayer;
                //characterRBCInfo.UnweldingHeightOffsetFactor = 100;
                characterRBCInfo.MaxLinearVelocity = 1000000;
                characterRBCInfo.MaxForce = 100000;
                characterRBCInfo.AllowedPenetrationDepth = 0.1f;
                characterRBCInfo.JumpHeight = 0.8f;


                CharacterRigidBody = new HkCharacterRigidBody(characterRBCInfo, MyGridPhysics.ShipMaxLinearVelocity(), body, isOnlyVertical);

                CharacterRigidBody.GetRigidBody().ContactPointCallbackEnabled = true;
                CharacterRigidBody.GetRigidBody().ContactPointCallback += RigidBody_ContactPointCallback;
                CharacterRigidBody.GetRigidBody().ContactPointCallbackDelay = 0;

                //CharacterRigidBody.GetHitRigidBody().ContactPointCallbackEnabled = true;
                //CharacterRigidBody.GetHitRigidBody().ContactPointCallback += RigidBody_ContactPointCallback;
                //CharacterRigidBody.GetHitRigidBody().ContactPointCallbackDelay = 0;

                //CharacterRigidBody.SetSupportDistance(10);
                //CharacterRigidBody.SetHardSupportDistance(10);

                characterRBCInfo.Dispose();
            }            
        }