Пример #1
0
        public void EnableFlyingState(bool enable)
        {
            float maxCharacterSpeed = MyGridPhysics.ShipMaxLinearVelocity() + this.m_maxSpeedRelativeToShip;

            this.m_physicsBody.ShapeChangeInProgress = true;
            this.EnableFlyingState(enable, maxCharacterSpeed, MyGridPhysics.ShipMaxLinearVelocity() + this.m_maxSpeedRelativeToShip, 9f);
            this.m_physicsBody.ShapeChangeInProgress = false;
        }
        public void EnableFlyingState(bool enable)
        {
            //multiply by constant because walking on max moving ship
            float maxCharacterWalkingSpeed = MyGridPhysics.ShipMaxLinearVelocity() + m_maxSpeedRelativeToShip;
            float maxCharacterFlyingSpeed  = MyGridPhysics.ShipMaxLinearVelocity() + m_maxSpeedRelativeToShip;
            float maxAcceleration          = 9; // why

            EnableFlyingState(enable, maxCharacterWalkingSpeed, maxCharacterFlyingSpeed, maxAcceleration);
        }
Пример #3
0
        public void EnableFlyingState(bool enable)
        {
            //multiply by constant because walking on max moving ship
            bool  shouldLimitSpeed         = Sync.IsServer;
            float maxCharacterWalkingSpeed = shouldLimitSpeed ? (MyGridPhysics.ShipMaxLinearVelocity() + m_maxSpeedRelativeToShip) : MyGridPhysics.MAX_SHIP_SPEED;
            float maxCharacterFlyingSpeed  = shouldLimitSpeed ? (MyGridPhysics.ShipMaxLinearVelocity() + m_maxSpeedRelativeToShip) : MyGridPhysics.MAX_SHIP_SPEED;
            float maxAcceleration          = 9; // why

            EnableFlyingState(enable, maxCharacterWalkingSpeed, maxCharacterFlyingSpeed, maxAcceleration);
        }
Пример #4
0
 public static void Postfix(ref MyPhysicsBody __instance)
 {
     if (SpeedLimitFix.Shared.isEnabled && __instance.RigidBody2 != null)
     {
         if (MySession.Static.OnlineMode == VRage.Game.MyOnlineModeEnum.OFFLINE)
         {
             __instance.RigidBody2.MaxLinearVelocity = MyGridPhysics.ShipMaxLinearVelocity() + 100;
         }
     }
 }
Пример #5
0
        public void ApplyGravity(Vector3 gravity)
        {
            HkCharacterRigidBody characterRigidBody = this.CharacterRigidBody;

            characterRigidBody.LinearVelocity += gravity * 0.01666667f;
            if (this.CharacterRigidBody.LinearVelocity.LengthSquared() > this.m_maxCharacterSpeedSq)
            {
                Vector3 linearVelocity = this.CharacterRigidBody.LinearVelocity;
                linearVelocity.Normalize();
                linearVelocity *= MyGridPhysics.ShipMaxLinearVelocity() + this.MaxSpeedRelativeToShip;
                this.CharacterRigidBody.LinearVelocity = linearVelocity;
            }
        }
        protected override void UpdateThrusts()
        {
            base.UpdateThrusts();

            ProfilerShort.Begin("MyJetpackThrustComponent.UpdateThrusts");
            if (Character != null &&
                Character.Physics != null &&
                Jetpack.TurnedOn &&
                (MySession.Static.LocalCharacter == Character ||
                 MySession.Static.ControlledEntity == Character ||
                 MySandboxGame.IsDedicated ||
                 (MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.Entity && (MySector.MainCamera.IsInFrustum(Character.PositionComp.WorldAABB) ||
                                                                                                  (Character.PositionComp.GetPosition() - MySector.MainCamera.Position).LengthSquared() < 100f))))
            {
                if (FinalThrust.LengthSquared() > 0.001f)
                {
                    if (Character.Physics.IsInWorld)
                    {
                        Character.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, FinalThrust, null, null);

                        if (MyPerGameSettings.EnableMultiplayerVelocityCompensation)
                        {
                            Vector3 velocity = Character.Physics.LinearVelocity;
                            float   maxCharacterSpeedRelativeToShip = Math.Max(Character.Definition.MaxSprintSpeed, Math.Max(Character.Definition.MaxRunSpeed, Character.Definition.MaxBackrunSpeed));
                            float   maxSpeed = (MyGridPhysics.ShipMaxLinearVelocity() + maxCharacterSpeedRelativeToShip) * (Sync.IsServer ? 1.0f : Sync.RelativeSimulationRatio);
                            if (velocity.LengthSquared() > maxSpeed * maxSpeed)
                            {
                                velocity.Normalize();
                                velocity *= maxSpeed;
                                Character.Physics.LinearVelocity = velocity;
                            }
                        }
                    }
                }

                const float stoppingVelocitySq = 0.001f * 0.001f;
                if (Character.Physics.Enabled)
                {
                    if (Character.Physics.LinearVelocity != Vector3.Zero && Character.Physics.LinearVelocity.LengthSquared() < stoppingVelocitySq)
                    {
                        Character.Physics.LinearVelocity = Vector3.Zero;
                        ControlThrustChanged             = true;
                    }
                }
            }
            ProfilerShort.End();
        }
        protected override void UpdateThrusts()
        {
            base.UpdateThrusts();

            ProfilerShort.Begin("MyJetpackThrustComponent.UpdateThrusts");
            if (Character != null &&
                Character.Physics != null &&
                Jetpack.TurnedOn &&
                (!Character.ControllerInfo.IsRemotelyControlled() || Sync.IsServer))
            {
                if (FinalThrust.LengthSquared() > 0.001f)
                {
                    if (Character.Physics.IsInWorld)
                    {
                        Character.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, FinalThrust, null, null);

                        if (MyPerGameSettings.EnableMultiplayerVelocityCompensation)
                        {
                            Vector3 velocity = Character.Physics.LinearVelocity;
                            float   maxCharacterSpeedRelativeToShip = Math.Max(Character.Definition.MaxSprintSpeed, Math.Max(Character.Definition.MaxRunSpeed, Character.Definition.MaxBackrunSpeed));
                            float   maxSpeed = (MyGridPhysics.ShipMaxLinearVelocity() + maxCharacterSpeedRelativeToShip) * (Sync.IsServer ? 1.0f : Sync.RelativeSimulationRatio);
                            if (velocity.LengthSquared() > maxSpeed * maxSpeed)
                            {
                                velocity.Normalize();
                                velocity *= maxSpeed;
                                Character.Physics.LinearVelocity = velocity;
                            }
                        }
                    }
                }

                const float stoppingVelocitySq = 0.001f * 0.001f;
                if (Character.Physics.Enabled)
                {
                    if (Character.Physics.LinearVelocity != Vector3.Zero && Character.Physics.LinearVelocity.LengthSquared() < stoppingVelocitySq)
                    {
                        Character.Physics.LinearVelocity = Vector3.Zero;
                        ControlThrustChanged             = true;
                    }
                }
            }
            ProfilerShort.End();
        }
        protected override void UpdateThrusts(bool enableDampers)
        {
            base.UpdateThrusts(enableDampers);

            ProfilerShort.Begin("MyJetpackThrustComponent.UpdateThrusts");
            if (Character != null &&
                Character.Physics != null &&
                Jetpack.TurnedOn)
            {
                if (FinalThrust.LengthSquared() > 0.0001f)
                {
                    if (Character.Physics.IsInWorld)
                    {
                        Character.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, FinalThrust, null, null);

                        Vector3 velocity = Character.Physics.LinearVelocity;
                        float   maxCharacterSpeedRelativeToShip = Math.Max(Character.Definition.MaxSprintSpeed, Math.Max(Character.Definition.MaxRunSpeed, Character.Definition.MaxBackrunSpeed));
                        float   maxSpeed = (MyGridPhysics.ShipMaxLinearVelocity() + maxCharacterSpeedRelativeToShip);
                        if (velocity.LengthSquared() > maxSpeed * maxSpeed)
                        {
                            velocity.Normalize();
                            velocity *= maxSpeed;
                            Character.Physics.LinearVelocity = velocity;
                        }
                    }
                }

                const float stoppingVelocitySq = 0.001f * 0.001f;
                if (Character.Physics.Enabled)
                {
                    if (Character.Physics.LinearVelocity != Vector3.Zero && Character.Physics.LinearVelocity.LengthSquared() < stoppingVelocitySq)
                    {
                        Character.Physics.LinearVelocity = Vector3.Zero;
                        ControlThrustChanged             = true;
                    }
                }
            }
            ProfilerShort.End();
        }
        protected override void CalculatePositionDifference(ulong clientId, out bool isValid, out bool correctServer, out Vector3D delta)
        {
            isValid       = true;
            correctServer = false;

            Vector3D clientData  = m_additionalServerClientData[clientId];
            MatrixD  worldMatrix = Entity.PositionComp.WorldMatrix;

            delta = m_additionalServerClientData[clientId] - worldMatrix.Translation;

            Vector3D currentMoveDistance = Entity.Physics.LinearVelocity / 60.0f;

            if (currentMoveDistance.Equals(-delta, 0.01))
            {
                return;
            }

            float deltaL = (float)((currentMoveDistance + delta).LengthSquared());

            float maxSpeed = 1.04f * MyGridPhysics.ShipMaxLinearVelocity();

            float maxMoveDistance = (maxSpeed * maxSpeed) / (60f * 60f);

            if (deltaL > (maxMoveDistance + 0.0001))
            {
                correctServer = true;
                return;

                isValid = false;
                delta   = Vector3D.Zero;
            }
            else if (deltaL > 0.1 * 0.1)
            {
                correctServer = true;
            }
        }
        protected override void CustomClientRead(uint timeStamp, ref MyTimeStampValues serverPositionAndOrientation, VRage.Library.Collections.BitStream stream)
        {
            bool hasSupport = stream.ReadBool();

            if (hasSupport)
            {
                long entityId = stream.ReadInt64();

                Vector3D serverDelta      = stream.ReadVector3D();
                Vector3D serverSupportPos = stream.ReadVector3D();

                if (!MyEntities.EntityExists(entityId))
                {
                    return;
                }

                MyEntity support = MyEntities.GetEntityById(entityId);

                MyTimeStampValues?clientTransform = m_timestamp.GetTransform(timeStamp);

                Vector3D   clientDelta    = Vector3.Zero;
                Vector3D   clientVelocity = Vector3D.Zero;
                Quaternion rotationComp   = Quaternion.Identity;

                if (clientTransform != null)
                {
                    if (m_supportTimeStamp == null)
                    {
                        return;
                    }
                    MyTimeStampValues?supportTransform = m_supportTimeStamp.GetTransform(timeStamp);

                    Vector3D supportPosition = support.PositionComp.WorldMatrix.Translation;

                    if (supportTransform.HasValue)
                    {
                        supportPosition = supportTransform.Value.Transform.Position;

                        if (supportTransform.Value.EntityId != entityId)
                        {
                            supportPosition = serverSupportPos;
                            return;
                        }
                    }

                    clientDelta    = supportPosition - clientTransform.Value.Transform.Position;
                    clientVelocity = clientTransform.Value.LinearVelocity;
                    rotationComp   = Quaternion.Inverse(clientTransform.Value.Transform.Rotation);
                }
                else
                {
                    m_character.PositionComp.SetWorldMatrix(serverPositionAndOrientation.Transform.TransformMatrix, null, true);
                    return;
                }

                MyTimeStampValues delta = new MyTimeStampValues();

                Quaternion.Multiply(ref serverPositionAndOrientation.Transform.Rotation, ref rotationComp, out delta.Transform.Rotation);

                delta.Transform.Position = clientDelta - serverDelta;
                delta.LinearVelocity     = serverPositionAndOrientation.LinearVelocity - clientVelocity;

                double deltaL = delta.Transform.Position.Length();

                //if difference is more than
                if (deltaL < (MyGridPhysics.ShipMaxLinearVelocity() * Sync.RelativeSimulationRatio))
                {
                    delta.Transform.Position = delta.Transform.Position * 0.2;
                    delta.Transform.Rotation = Quaternion.Slerp(delta.Transform.Rotation, Quaternion.Identity, 0.2f);
                }


                Quaternion normalized = delta.Transform.Rotation;
                normalized.Normalize();
                delta.Transform.Rotation = normalized;
                normalized = serverPositionAndOrientation.Transform.Rotation;
                normalized.Normalize();
                serverPositionAndOrientation.Transform.Rotation = normalized;

                Quaternion clientNormalized = clientTransform.Value.Transform.Rotation;
                clientNormalized.Normalize();

                double eps = 0.001;
                if (Math.Abs(Quaternion.Dot(serverPositionAndOrientation.Transform.Rotation, clientNormalized)) < 1 - eps && m_character.IsDead == false)
                {
                    Quaternion currentOrientation = Quaternion.CreateFromForwardUp(m_character.WorldMatrix.Forward, m_character.WorldMatrix.Up);
                    Quaternion.Multiply(ref delta.Transform.Rotation, ref currentOrientation, out currentOrientation);

                    MatrixD matrix        = MatrixD.CreateFromQuaternion(currentOrientation);
                    MatrixD currentMatrix = m_character.PositionComp.WorldMatrix;
                    currentMatrix.Translation = Vector3D.Zero;

                    if (currentMatrix.EqualsFast(ref matrix) == false)
                    {
                        if (m_character.Physics.CharacterProxy != null)
                        {
                            m_character.Physics.CharacterProxy.Forward = matrix.Forward;
                            m_character.Physics.CharacterProxy.Up      = matrix.Up;
                        }
                    }
                }

                if (deltaL > (MyGridPhysics.ShipMaxLinearVelocity() * Sync.RelativeSimulationRatio))
                {
                    m_character.PositionComp.SetPosition(serverPositionAndOrientation.Transform.Position);
                    m_character.Physics.LinearVelocity = serverPositionAndOrientation.LinearVelocity;
                    m_timestamp.OverwriteServerPosition(timeStamp, ref serverPositionAndOrientation);
                    return;
                }
                else if (deltaL > 5.0f * MyTimestampHelper.POSITION_TOLERANCE)
                {
                    m_character.CacheMoveDelta(ref delta.Transform.Position);
                }

                m_character.Physics.LinearVelocity += delta.LinearVelocity;

                m_timestamp.UpdateDeltaPosition(timeStamp, ref delta);
            }
            else
            {
                base.CustomClientRead(timeStamp, ref serverPositionAndOrientation, stream);
            }
        }
Пример #11
0
        public bool TrySpawnParticle(Vector3 position, Vector3 normal, string particleName)
        {
            if (!MyFakes.ENABLE_DRIVING_PARTICLES)
            {
                return(false);
            }

            MyWheel wheel = Entity as MyWheel;

            if (wheel == null)
            {
                return(false);
            }

            if (MyUtils.GetRandomInt(10) < 5)//spawn only about 20% of particles
            {
                return(false);
            }
            var speedMultiplier = wheel.GetTopMostParent().Physics.LinearVelocity.Length() / MyGridPhysics.ShipMaxLinearVelocity();
            var currentTime     = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            if (currentTime - m_lastEffectCreationTime < 5)
            {
                return(false);
            }

            MyParticleEffect drivingEffect = null;

            if (!MyParticlesManager.TryCreateParticleEffect(particleName, out drivingEffect))
            {
                return(false);
            }

            m_lastEffectCreationTime       = currentTime;
            m_lastGlobalEffectCreationTime = m_lastEffectCreationTime;

            drivingEffect.WorldMatrix = MatrixD.CreateWorld(position, normal, Vector3.CalculatePerpendicularVector(normal));
            var speedScaleMultiplier = 1.0f + speedMultiplier * 6.0f;

            drivingEffect.UserScale = speedScaleMultiplier;

            return(true);
        }
Пример #12
0
        public override void UpdateBeforeSimulation()
        {
            return;

            base.UpdateBeforeSimulation();

            if (m_particleSpawnCounter-- > 0)
            {
                return;
            }

            var entity = MySession.Static.ControlledEntity as MyEntity;

            if (entity == null)
            {
                return;
            }

            var controlledEntity = entity.GetTopMostParent();

            if (controlledEntity == null)
            {
                return;
            }

            try
            {
                ProfilerShort.Begin("Grassland.UpdateBeforeSimulation");

                m_particleSpawnCounter = (int)Math.Round(m_particleSpawnCounter + m_particleSpawnCounter * m_particleSpawnIntervalRandomness * (MyRandom.Instance.NextFloat() * 2.0f - 1.0f));
                if (MyRandom.Instance.FloatNormal() <= m_particleDensity)
                {
                    return;
                }

                var      cameraPosition = MySector.MainCamera.Position;
                MyPlanet nearestPlanet  = MyGravityProviderSystem.GetNearestPlanet(cameraPosition);
                Vector3D naturalGravity = nearestPlanet.GetWorldGravityGrid(MySector.MainCamera.Position);
                if (naturalGravity.Dot(MySector.DirectionToSunNormalized) > 0) // Only spawn during the day
                {
                    return;
                }

                var velocity = (MySession.Static.GetCameraControllerEnum() != MyCameraControllerEnum.Entity &&
                                MySession.Static.GetCameraControllerEnum() != MyCameraControllerEnum.ThirdPersonSpectator
                                ? Vector3.Zero : controlledEntity.Physics.LinearVelocity);
                var speed = velocity.Length();

                var cameraPositionLocal = Vector3D.Transform(cameraPosition, MatrixD.Invert(nearestPlanet.WorldMatrix));
                //Vector3D nearestSurfacePointLocal = nearestPlanet.GetClosestSurfacePointLocal(cameraPosition);
                //	Vector3D nearestSurfacePointWorld = Vector3D.Transform(nearestSurfacePointLocal, nearestPlanet.WorldMatrix);
                //		bool test = nearestPlanet.IsFloraAtPosition(nearestSurfacePointLocal);

                var   currentCharacter        = controlledEntity as MyCharacter;
                float characterFlyingMaxSpeed = (currentCharacter != null) ? currentCharacter.Physics.CharacterProxy.CharacterFlyingMaxLinearVelocity() : MyGridPhysics.ShipMaxLinearVelocity();

                Vector3 halfExtents = Vector3.One * m_particleSpawnDistance;
                if (speed / characterFlyingMaxSpeed > 1.0f)
                {
                    halfExtents += 10.0f * velocity / characterFlyingMaxSpeed;
                }

                var entityTranslation = cameraPosition;
                var searchPosition    = entityTranslation + velocity;

                MyPhysics.GetPenetrationsBox(ref halfExtents, ref searchPosition, ref Quaternion.Identity, m_bodyCollisions, MyPhysics.CollisionLayers.NotCollideWithStaticLayer);

                var  spawnPosition      = default(Vector3D);
                bool spawnPositionFound = false;

                foreach (var foundEntity in m_bodyCollisions)
                {
                    var environmentItems = foundEntity.Body.GetEntity(foundEntity.ShapeKey) as MyEnvironmentItems;
                    if (environmentItems != null)
                    {
                        environmentItems.GetAllItemsInRadius(searchPosition, m_particleSpawnDistance, m_tmpItemInfos);
                    }
                }

                if (m_tmpItemInfos.Count != 0)
                {
                    int selectedTreeIndex = MyRandom.Instance.Next(0, m_tmpItemInfos.Count - 1);
                    spawnPosition      = m_tmpItemInfos[selectedTreeIndex].Transform.Position;
                    spawnPositionFound = true;
                }

                if (!spawnPositionFound)
                {
                    return;
                }

                var spawnedParticle = Spawn(spawnPosition);

                if (spawnedParticle == null)
                {
                    return;
                }

                InitializePath(spawnedParticle);
            }
            finally
            {
                m_bodyCollisions.Clear();

                ProfilerShort.End();
            }
        }
Пример #13
0
        public void ServerResponse(uint timeStamp, ref MyTimeStampValues serverPositionAndOrientation)
        {
            if (timeStamp < m_lastTSFromServer)
            {
                return;
            }

            if (m_timeStampData.ContainsKey(timeStamp) == false)
            {
                m_entity.PositionComp.SetWorldMatrix(serverPositionAndOrientation.Transform.TransformMatrix, null, true);
                return;
            }

            MyTimeStampValues cachedData = m_timeStampData[timeStamp];

            MatrixD worldMatrix = m_entity.PositionComp.WorldMatrix;

            MyTimeStampValues delta = new MyTimeStampValues();

            delta.Transform.Position = serverPositionAndOrientation.Transform.Position - cachedData.Transform.Position;

            double deltaL = delta.Transform.Position.Length();

            MyCharacter character = (m_entity as MyCharacter);

            cachedData.Transform.Rotation = Quaternion.Inverse(cachedData.Transform.Rotation);
            Quaternion.Multiply(ref serverPositionAndOrientation.Transform.Rotation, ref cachedData.Transform.Rotation, out delta.Transform.Rotation);
            if (deltaL < (MyGridPhysics.ShipMaxLinearVelocity() / (60f * Sync.RelativeSimulationRatio)))
            {
                delta.Transform.Position = delta.Transform.Position * 0.2;
            }
            delta.Transform.Rotation = Quaternion.Slerp(delta.Transform.Rotation, Quaternion.Identity, 0.2f);
            Vector3D position = worldMatrix.Translation;

            position += delta.Transform.Position;

            delta.LinearVelocity = serverPositionAndOrientation.LinearVelocity - cachedData.LinearVelocity;

            delta.AngularVelocity = serverPositionAndOrientation.AngularVelocity - cachedData.AngularVelocity;

            double deltaVelocity = delta.LinearVelocity.LengthSquared();

            if (deltaVelocity > 0.1 * 0.1)
            {
                m_entity.Physics.LinearVelocity += delta.LinearVelocity;
            }

            deltaVelocity = delta.AngularVelocity.LengthSquared();

            if (deltaVelocity > 0.01 * 0.01)
            {
                m_entity.Physics.AngularVelocity += delta.AngularVelocity;
            }

            Quaternion orientation = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up);


            Quaternion normalized = cachedData.Transform.Rotation;

            normalized.Normalize();
            cachedData.Transform.Rotation = normalized;
            normalized = serverPositionAndOrientation.Transform.Rotation;
            normalized.Normalize();
            serverPositionAndOrientation.Transform.Rotation = normalized;

            double eps = 0.001;

            if (Math.Abs(Quaternion.Dot(serverPositionAndOrientation.Transform.Rotation, cachedData.Transform.Rotation)) < 1 - eps)
            {
                Quaternion.Multiply(ref delta.Transform.Rotation, ref orientation, out orientation);
                MatrixD  matrix        = MatrixD.CreateFromQuaternion(orientation);
                MatrixD  currentMatrix = m_entity.PositionComp.WorldMatrix;
                Vector3D translation   = currentMatrix.Translation;
                currentMatrix.Translation = Vector3D.Zero;
                if (currentMatrix.EqualsFast(ref matrix, 0.01) == false)
                {
                    matrix.Translation = translation;
                    m_entity.PositionComp.SetWorldMatrix(matrix, null, true);
                }
            }


            if (deltaL > (MyGridPhysics.ShipMaxLinearVelocity() / (60f * Sync.RelativeSimulationRatio)))
            {
                m_entity.PositionComp.SetPosition(serverPositionAndOrientation.Transform.Position);
            }
            else if (deltaL > POSITION_TOLERANCE)
            {
                if (m_entity is MyCharacter)
                {
                    (m_entity as MyCharacter).CacheMoveDelta(ref delta.Transform.Position);
                }
                else
                {
                    m_entity.PositionComp.SetPosition(position);
                }
            }


            UpdateDeltaPosition(timeStamp, ref delta);

            m_lastTSFromServer = timeStamp;
        }
Пример #14
0
 public void EnableLadderState(bool enable)
 {
     EnableLadderState(enable, MyGridPhysics.ShipMaxLinearVelocity(), 1);
 }
Пример #15
0
 public float CharacterWalkingMaxLinearVelocity()
 {
     return(m_maxSpeedRelativeToShip + MyGridPhysics.ShipMaxLinearVelocity());
 }
Пример #16
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();
            }
        }
Пример #17
0
 public float CharacterFlyingMaxLinearVelocity() =>
 (this.m_maxSpeedRelativeToShip + MyGridPhysics.ShipMaxLinearVelocity());
Пример #18
0
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (!MyFakes.ENABLE_PLANET_FIREFLIES)
            {
                return;
            }

            if (m_particleSpawnCounter-- > 0)
            {
                return;
            }

            m_particleSpawnCounter = 0;

            var entity = MySession.Static.ControlledEntity as MyEntity;

            if (entity == null)
            {
                return;
            }

            var controlledEntity = entity.GetTopMostParent();

            if (controlledEntity == null)
            {
                return;
            }

            try
            {
                ProfilerShort.Begin("Fireflies.Spawn");

                m_particleSpawnCounter = (int)Math.Round(m_particleSpawnCounter + m_particleSpawnCounter * m_particleSpawnIntervalRandomness * (MyRandom.Instance.NextFloat() * 2.0f - 1.0f));
                float normalVar = (MyRandom.Instance.FloatNormal() + 3.0f) / 6.0f;
                if (normalVar > m_particleDensity)
                {
                    return;
                }

                var naturalGravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(MySector.MainCamera.Position);
                if (naturalGravity.Dot(MySector.DirectionToSunNormalized) <= 0)                 // Only spawn at night and on planets
                {
                    return;
                }

                var velocity = (MySession.Static.GetCameraControllerEnum() != MyCameraControllerEnum.Entity &&
                                MySession.Static.GetCameraControllerEnum() != MyCameraControllerEnum.ThirdPersonSpectator
                                                                ? Vector3.Zero : controlledEntity.Physics.LinearVelocity);
                var speed = velocity.Length();

                var currentCharacter = controlledEntity as MyCharacter;

                float characterFlyingMaxSpeed = MyGridPhysics.ShipMaxLinearVelocity();

                if (currentCharacter != null && currentCharacter.Physics != null && currentCharacter.Physics.CharacterProxy != null)
                {
                    characterFlyingMaxSpeed = currentCharacter.Physics.CharacterProxy.CharacterFlyingMaxLinearVelocity();
                }

                Vector3 halfExtents = Vector3.One * m_particleSpawnDistance;
                if (speed / characterFlyingMaxSpeed > 1.0f)
                {
                    halfExtents += 10.0f * velocity / characterFlyingMaxSpeed;
                }

                var entityTranslation = MySector.MainCamera.Position;
                var searchPosition    = entityTranslation + velocity;

                MyPlanet planet = MyGamePruningStructure.GetClosestPlanet(MySector.MainCamera.Position);

                if (planet == null)
                {
                    return;
                }

                // TODO: Re-do this using new system.
                Vector3D cameraPosition = MySector.MainCamera.Position;
                //var foundEnvironmentItems = planet.GetEnvironmentItemsAtPosition(ref cameraPosition);

                /*foreach (var environmentItems in foundEnvironmentItems)
                 *  environmentItems.GetAllItemsInRadius(searchPosition, m_particleSpawnDistance, m_tmpItemInfos);*/

                var  spawnPosition      = default(Vector3D);
                bool spawnPositionFound = m_tmpItemInfos.Count != 0;
                if (spawnPositionFound)
                {
                    int selectedTreeIndex = MyRandom.Instance.Next(0, m_tmpItemInfos.Count - 1);
                    spawnPosition      = m_tmpItemInfos[selectedTreeIndex].Transform.Position;
                    spawnPositionFound = true;
                }
                else
                {
                    return;
                }

                var spawnedParticle = Spawn(spawnPosition);

                if (spawnedParticle == null)
                {
                    return;
                }

                InitializePath(spawnedParticle);
            }
            finally
            {
                m_bodyCollisions.Clear();
                m_tmpItemInfos.Clear();

                ProfilerShort.End();
            }
        }
Пример #19
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 = new float?(), HkRagdoll ragDoll = null)
 {
     this.m_isDynamic              = isDynamic;
     this.m_physicsBody            = body;
     this.m_mass                   = mass;
     this.m_maxImpulse             = maxImpulse;
     this.m_maxSpeedRelativeToShip = maxSpeedRelativeToShip;
     if (!isCapsule)
     {
         HkBoxShape shape = new HkBoxShape(new Vector3(characterWidth / 2f, characterHeight / 2f, characterWidth / 2f));
         if (!this.m_isDynamic)
         {
             this.CharacterPhantom = new HkSimpleShapePhantom((HkShape)shape, 0x12);
         }
         this.m_characterShape = (HkShape)shape;
     }
     else
     {
         this.m_characterShape          = CreateCharacterShape(characterHeight, characterWidth, characterHeight + headHeight, headSize, 0f, 0f, false);
         this.m_characterCollisionShape = CreateCharacterShape(characterHeight * 0.9f, characterWidth * 0.9f, (characterHeight * 0.9f) + headHeight, headSize * 0.9f, 0f, 0f, false);
         this.m_crouchShape             = CreateCharacterShape(characterHeight, characterWidth, characterHeight + headHeight, headSize, 0f, 1f, false);
         if (!this.m_isDynamic)
         {
             this.CharacterPhantom = new HkSimpleShapePhantom(this.m_characterShape, 0x12);
         }
     }
     if (!this.m_isDynamic)
     {
         HkCharacterProxyCinfo characterProxyCinfo = new HkCharacterProxyCinfo {
             StaticFriction                = 1f,
             DynamicFriction               = 1f,
             ExtraDownStaticFriction       = 1000f,
             MaxCharacterSpeedForSolver    = 10000f,
             RefreshManifoldInCheckSupport = true,
             Up                = up,
             Forward           = forward,
             UserPlanes        = 4,
             MaxSlope          = MathHelper.ToRadians(maxSlope),
             Position          = position,
             CharacterMass     = mass,
             CharacterStrength = 100f,
             ShapePhantom      = this.CharacterPhantom
         };
         this.CharacterProxy = new HkCharacterProxy(characterProxyCinfo);
         characterProxyCinfo.Dispose();
     }
     else
     {
         HkCharacterRigidBodyCinfo characterRigidBodyCinfo = new HkCharacterRigidBodyCinfo {
             Shape                   = this.m_characterShape,
             CrouchShape             = this.m_crouchShape,
             Friction                = 0f,
             MaxSlope                = MathHelper.ToRadians(maxSlope),
             Up                      = up,
             Mass                    = mass,
             CollisionFilterInfo     = 0x12,
             MaxLinearVelocity       = 1000000f,
             MaxForce                = (maxForce != null) ? maxForce.Value : 100000f,
             AllowedPenetrationDepth = MyFakes.ENABLE_LIMITED_CHARACTER_BODY ? 0.3f : 0.1f,
             JumpHeight              = 0.8f
         };
         float maxCharacterSpeed = MyGridPhysics.ShipMaxLinearVelocity() + this.m_maxSpeedRelativeToShip;
         this.CharacterRigidBody    = new HkCharacterRigidBody(characterRigidBodyCinfo, maxCharacterSpeed, body);
         this.m_maxCharacterSpeedSq = maxCharacterSpeed * maxCharacterSpeed;
         this.CharacterRigidBody.GetRigidBody().ContactPointCallbackEnabled = true;
         this.CharacterRigidBody.GetRigidBody().ContactPointCallback       -= new ContactPointEventHandler(this.RigidBody_ContactPointCallback);
         this.CharacterRigidBody.GetRigidBody().ContactPointCallback       += new ContactPointEventHandler(this.RigidBody_ContactPointCallback);
         this.CharacterRigidBody.GetRigidBody().ContactPointCallbackDelay   = 0;
         Matrix inertiaTensor = this.CharacterRigidBody.GetHitRigidBody().InertiaTensor;
         inertiaTensor.M11 = 1000f;
         inertiaTensor.M22 = 1000f;
         inertiaTensor.M33 = 1000f;
         this.CharacterRigidBody.GetHitRigidBody().InertiaTensor = inertiaTensor;
         characterRigidBodyCinfo.Dispose();
     }
 }
        private void DrawAtmosphericEntryEffect()
        {
            var naturalGravity          = MyGravityProviderSystem.CalculateNaturalGravityInPoint(m_grid.PositionComp.GetPosition());
            var naturalGravityMagnitude = naturalGravity.Length();

            bool noPhysics        = m_grid.Physics == null;
            bool recentlyHitVoxel = MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastVoxelContactTime < m_atmosphericEffectVoxelContactDelay;
            bool notNearPlanet    = naturalGravityMagnitude <= 0;
            bool tooLowSpeed      = !noPhysics && (m_grid.Physics.LinearVelocity.Length() < m_atmosphericEffectMinSpeed);

            if (noPhysics || recentlyHitVoxel || notNearPlanet || tooLowSpeed)
            {
                if (m_atmosphericEffect != null)
                {
                    MyParticlesManager.RemoveParticleEffect(m_atmosphericEffect);
                    m_atmosphericEffect = null;
                }

                return;
            }
            var currentVelocity          = m_grid.Physics.LinearVelocity;
            var currentVelocityDirection = Vector3.Normalize(currentVelocity);
            var currentSpeed             = currentVelocity.Length();

            if (m_atmosphericEffect == null)
            {
                if (!MyParticlesManager.TryCreateParticleEffect(52, out m_atmosphericEffect))
                {
                    return;
                }
            }

            BoundingBox worldAABB           = (BoundingBox)m_grid.PositionComp.WorldAABB;
            var         aabbCenter          = worldAABB.Center;
            var         directionFaceCenter = new Vector3();

            Debug.Assert(m_tmpCornerList.Count == 0);
            foreach (var corner in worldAABB.GetCorners())
            {
                var centerToCorner = corner - aabbCenter;
                if (centerToCorner.Dot(currentVelocityDirection) > 0.01f)
                {
                    m_tmpCornerList.Add(corner);
                    directionFaceCenter += corner;
                    if (m_tmpCornerList.Count == 4)
                    {
                        break;
                    }
                }
            }
            if (m_tmpCornerList.Count > 0)
            {
                directionFaceCenter /= m_tmpCornerList.Count;
            }

            Plane plane = new Plane(directionFaceCenter, -currentVelocityDirection);

            m_tmpCornerList.Clear();
            var   startPosition     = m_grid.Physics.CenterOfMassWorld;
            float?intersectDistance = new Ray(startPosition, currentVelocityDirection).Intersects(plane);

            m_lastWorkingIntersectDistance = intersectDistance ?? m_lastWorkingIntersectDistance;
            var intersectPoint = startPosition + 0.875f * currentVelocityDirection * m_lastWorkingIntersectDistance;

            Matrix worldMatrix = Matrix.Identity;

            worldMatrix.Translation = intersectPoint;
            worldMatrix.Forward     = currentVelocityDirection;
            var forwardPerpendicular = Vector3.Transform(currentVelocityDirection, Quaternion.CreateFromAxisAngle(m_grid.PositionComp.WorldMatrix.Left, (float)Math.PI / 2.0f));

            worldMatrix.Up   = Vector3.Normalize(Vector3.Reject(m_grid.PositionComp.WorldMatrix.Left, forwardPerpendicular));
            worldMatrix.Left = worldMatrix.Up.Cross(worldMatrix.Forward);

            var atmosphericDensityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(m_grid.PositionComp.GetPosition());

            m_atmosphericEffect.UserScale           = (float)worldAABB.ProjectedArea(currentVelocityDirection) / (float)Math.Pow(38.0 * m_grid.GridSize, 2.0);
            m_atmosphericEffect.UserAxisScale       = Vector3.Normalize(new Vector3(1.0f, 1.0f, 1.0f + 1.5f * (m_grid.Physics.LinearVelocity.Length() - m_atmosphericEffectMinSpeed) / (MyGridPhysics.ShipMaxLinearVelocity() - m_atmosphericEffectMinSpeed)));
            m_atmosphericEffect.WorldMatrix         = worldMatrix;
            m_atmosphericEffect.UserColorMultiplier = new Vector4(MathHelper.Clamp((currentSpeed - m_atmosphericEffectMinSpeed) / (m_atmosphericEffectMinSpeed * 0.5f) * (float)Math.Pow(atmosphericDensityMultiplier, 1.5), 0.0f, m_atmosphericEffectMinFade));
        }
Пример #21
0
        private unsafe void DrawAtmosphericEntryEffect()
        {
            int  num1;
            bool flag  = (MySandboxGame.TotalGamePlayTimeInMilliseconds - this.m_lastVoxelContactTime) < 0x1388;
            bool flag2 = !(MyGravityProviderSystem.CalculateNaturalGravityInPoint(this.m_grid.PositionComp.GetPosition()).Length() != 0f);
            bool flag1 = ReferenceEquals(this.m_grid.Physics, null);

            if (!flag1)
            {
                num1 = (int)(this.m_grid.Physics.LinearVelocity.Length() < 75f);
            }
            else
            {
                num1 = 0;
            }
            bool flag3 = (bool)num1;

            if (((flag1 | flag) | flag2) | flag3)
            {
                if (this.m_atmosphericEffect != null)
                {
                    MyParticlesManager.RemoveParticleEffect(this.m_atmosphericEffect, false);
                    this.m_atmosphericEffect = null;
                }
            }
            else
            {
                Vector3     linearVelocity = this.m_grid.Physics.LinearVelocity;
                Vector3     v         = Vector3.Normalize(linearVelocity);
                float       num2      = linearVelocity.Length();
                BoundingBox worldAABB = (BoundingBox)this.m_grid.PositionComp.WorldAABB;
                Vector3     center    = worldAABB.Center;
                Vector3     position  = new Vector3();
                foreach (Vector3 vector8 in worldAABB.GetCorners())
                {
                    Vector3 vector9 = vector8 - center;
                    if (vector9.Dot(v) > 0.01f)
                    {
                        m_tmpCornerList.Add(vector8);
                        position += vector8;
                        if (m_tmpCornerList.Count == 4)
                        {
                            break;
                        }
                    }
                }
                if (m_tmpCornerList.Count > 0)
                {
                    position /= (float)m_tmpCornerList.Count;
                }
                Plane plane = new Plane(position, -v);
                m_tmpCornerList.Clear();
                Vector3D centerOfMassWorld = this.m_grid.Physics.CenterOfMassWorld;
                float?   nullable2         = new Ray((Vector3)centerOfMassWorld, v).Intersects(plane);
                this.m_lastWorkingIntersectDistance = (nullable2 != null) ? nullable2.GetValueOrDefault() : this.m_lastWorkingIntersectDistance;
                Matrix identity = Matrix.Identity;
                identity.Translation = (Vector3)(centerOfMassWorld + ((0.875f * v) * this.m_lastWorkingIntersectDistance));
                identity.Forward     = v;
                Vector3 direction = Vector3.Transform(v, Quaternion.CreateFromAxisAngle((Vector3)this.m_grid.PositionComp.WorldMatrix.Left, 1.570796f));
                identity.Up = Vector3.Normalize(Vector3.Reject((Vector3)this.m_grid.PositionComp.WorldMatrix.Left, direction));
                Matrix *matrixPtr1 = (Matrix *)ref identity;
                matrixPtr1.Left = identity.Up.Cross(identity.Forward);
                float num3 = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(this.m_grid.PositionComp.GetPosition());
                if ((this.m_atmosphericEffect != null) || MyParticlesManager.TryCreateParticleEffect("Dummy", identity, out this.m_atmosphericEffect))
                {
                    this.m_atmosphericEffect.UserScale           = worldAABB.ProjectedArea(v) / ((float)Math.Pow(38.0 * this.m_grid.GridSize, 2.0));
                    this.m_atmosphericEffect.UserAxisScale       = Vector3.Normalize(new Vector3(1f, 1f, 1f + ((1.5f * (this.m_grid.Physics.LinearVelocity.Length() - 75f)) / (MyGridPhysics.ShipMaxLinearVelocity() - 75f))));
                    this.m_atmosphericEffect.UserColorMultiplier = new Vector4(MathHelper.Clamp((float)(((num2 - 75f) / 37.5f) * ((float)Math.Pow((double)num3, 1.5))), (float)0f, (float)0.85f));
                }
            }
        }
        protected override void CalculatePositionDifference(ulong clientId, out bool isValid, out bool correctServer, out Vector3D delta)
        {
            delta         = Vector3D.Zero;
            isValid       = true;
            correctServer = false;

            ClientData clientData  = m_additionalServerClientData[clientId];
            MatrixD    worldMatrix = Entity.PositionComp.WorldMatrix;

            float maxCharacterSpeedRelativeToShip = Math.Max(m_character.Definition.MaxSprintSpeed, Math.Max(m_character.Definition.MaxRunSpeed, m_character.Definition.MaxBackrunSpeed));
            float maxSpeed = 1.04f * (MyGridPhysics.ShipMaxLinearVelocity() + maxCharacterSpeedRelativeToShip);

            if (m_haveJetpack == false)
            {
                maxSpeed = 1.04f * maxCharacterSpeedRelativeToShip;
            }

            float maxMoveDistance = (float)((maxSpeed * maxSpeed) / (60f * 60f));

            if (clientData.HasSupport)
            {
                MyEntity support = MySupportHelper.FindSupportForCharacterAABB(m_character);
                if (support != null)
                {
                    Vector3D characterDelta = m_serverClientData[clientId].Transform.Position - m_character.PositionComp.GetPosition();
                    Vector3D supportDelta   = clientData.SupportPosition - support.PositionComp.GetPosition();
                    delta = characterDelta - supportDelta;
                }
                else
                {
                    isValid = false;
                }
            }
            else
            {
                correctServer = true;
                delta         = m_serverClientData[clientId].Transform.Position - worldMatrix.Translation;
                return;
            }

            double deltaL = delta.LengthSquared();

            if (deltaL > 1.3f * (maxMoveDistance + 0.0001))
            {
                isValid       = true;
                correctServer = true;
                //  delta = Vector3D.Zero;
            }
            else if (deltaL > 0.05 * 0.05)
            {
                if (m_commandsApplied.ContainsKey(clientId) == false || m_commandsApplied[clientId] == false)
                {
                    isValid = false;
                    delta   = Vector3D.Zero;
                }
                else
                {
                    correctServer = true;
                }
            }
            m_commandsApplied[clientId] = false;
        }
        public bool TrySpawnParticle(Vector3D worldPosition, MyParticleEffectsIDEnum particleEffect = MyParticleEffectsIDEnum.Collision_Meteor)
        {
            if (!MyFakes.ENABLE_DRIVING_PARTICLES)
            {
                return(false);
            }

            MyWheel wheel = Entity as MyWheel;

            if (wheel == null)
            {
                return(false);
            }

            var speedMultiplier = wheel.GetTopMostParent().Physics.LinearVelocity.Length() / MyGridPhysics.ShipMaxLinearVelocity();
            var currentTime     = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            if (currentTime - m_lastGlobalEffectCreationTime < 5 ||
                currentTime - m_lastEffectCreationTime < m_effectCreationInterval * MyUtils.GetRandomFloat(0.9f * (1.5f - speedMultiplier), 1.1f / (0.25f + speedMultiplier)))
            {
                return(false);
            }

            MyParticleEffect drivingEffect = null;

            if (!MyParticlesManager.TryCreateParticleEffect((int)particleEffect, out drivingEffect))
            {
                return(false);
            }

            m_lastEffectCreationTime       = currentTime;
            m_lastGlobalEffectCreationTime = m_lastEffectCreationTime;

            drivingEffect.WorldMatrix = MatrixD.CreateTranslation(worldPosition);
            drivingEffect.Preload     = 1.0f;
            var speedScaleMultiplier = 1.0f + speedMultiplier * 6.0f;

            drivingEffect.UserScale = 0.25f * speedScaleMultiplier;

            return(true);
        }
Пример #24
0
        public bool TrySpawnParticle(Vector3D worldPosition, MyTuple <int, ContactPropertyParticleProperties> particle)
        {
            if (!MyFakes.ENABLE_DRIVING_PARTICLES)
            {
                return(false);
            }

            MyWheel wheel = Entity as MyWheel;

            if (wheel == null)
            {
                return(false);
            }

            if (MyUtils.GetRandomInt(10) < 8)//spawn only about 20% of particles
            {
                return(false);
            }
            var speedMultiplier = wheel.GetTopMostParent().Physics.LinearVelocity.Length() / MyGridPhysics.ShipMaxLinearVelocity();
            var currentTime     = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            if (currentTime - m_lastEffectCreationTime < 50)
            {
                return(false);
            }

            MyParticleEffect drivingEffect = null;

            if (!MyParticlesManager.TryCreateParticleEffect(particle.Item1, out drivingEffect))
            {
                return(false);
            }

            m_lastEffectCreationTime       = currentTime;
            m_lastGlobalEffectCreationTime = m_lastEffectCreationTime;

            drivingEffect.WorldMatrix = MatrixD.CreateTranslation(worldPosition);
            var speedScaleMultiplier = 1.0f + speedMultiplier * 6.0f;

            if (particle.Item2 != null)
            {
                drivingEffect.UserScale           = particle.Item2.SizeMultiplier * speedScaleMultiplier;
                drivingEffect.UserColorMultiplier = particle.Item2.ColorMultiplier;
                drivingEffect.SetPreload(particle.Item2.Preload);
            }

            return(true);
        }