コード例 #1
0
        protected override void UpdateThrusts()
        {
            base.UpdateThrusts();

            if (CubeGrid != null && CubeGrid.Physics != null &&
                (CubeGrid.GridSystems.ControlSystem.IsLocallyControlled ||
                 (!CubeGrid.GridSystems.ControlSystem.IsControlled) ||
                 (CubeGrid.GridSystems.ControlSystem.IsControlled && (MySector.MainCamera.IsInFrustum(CubeGrid.PositionComp.WorldAABB) || (CubeGrid.PositionComp.GetPosition() - MySector.MainCamera.Position).LengthSquared() < 100f))))
            {
                if (CubeGrid.Physics.Enabled)
                {
                    if (FinalThrust.LengthSquared() > 0.001f)
                    {
                        var thrust = FinalThrust;
                        if (CubeGrid.Physics.IsWelded) //only reliable variant
                        {
                            thrust = Vector3.TransformNormal(thrust, CubeGrid.WorldMatrix);
                            thrust = Vector3.TransformNormal(thrust, Matrix.Invert(CubeGrid.Physics.RigidBody.GetRigidBodyMatrix()));
                        }
                        CubeGrid.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, thrust, null, null);
                    }

                    const float stoppingVelocitySq = 0.001f * 0.001f;
                    if (CubeGrid.Physics.LinearVelocity != Vector3.Zero && CubeGrid.Physics.LinearVelocity.LengthSquared() < stoppingVelocitySq && CubeGrid.Physics.RigidBody.IsActive)
                    {
                        CubeGrid.Physics.LinearVelocity = Vector3.Zero;
                    }
                }
            }
        }
コード例 #2
0
        protected override void UpdateThrusts(bool enableDampeners)
        {
            base.UpdateThrusts(enableDampeners);

            ProfilerShort.Begin("ThrusterBlockComponent.UpdateThrusts");
            if (CubeGrid != null && CubeGrid.Physics != null)
            {
                if (CubeGrid.Physics.Enabled)
                {
                    if (FinalThrust.LengthSquared() > 0.0001f)
                    {
                        var thrust = FinalThrust;
                        if (CubeGrid.Physics.IsWelded) //only reliable variant
                        {
                            thrust = Vector3.TransformNormal(thrust, CubeGrid.WorldMatrix);
                            thrust = Vector3.TransformNormal(thrust, Matrix.Invert(CubeGrid.Physics.RigidBody.GetRigidBodyMatrix()));
                        }

                        CubeGrid.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, thrust, null, null);
                        m_index++;

                        Vector3 velocity = CubeGrid.Physics.LinearVelocity;
                        float   maxSpeed = CubeGrid.GridSizeEnum == MyCubeSize.Large ? MyGridPhysics.LargeShipMaxLinearVelocity() : MyGridPhysics.SmallShipMaxLinearVelocity();

                        if (velocity.LengthSquared() > maxSpeed * maxSpeed)
                        {
                            velocity.Normalize();
                            velocity *= maxSpeed;
                            CubeGrid.Physics.LinearVelocity = velocity;
                        }
                    }
                }
            }
            ProfilerShort.End();
        }
コード例 #3
0
        protected override void UpdateThrusts()
        {
            base.UpdateThrusts();

            if (Character != null &&
                Character.Physics != null &&
                Jetpack.TurnedOn &&
                (MySession.LocalCharacter == Character ||
                 (MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Entity && (MySector.MainCamera.IsInFrustum(Character.PositionComp.WorldAABB) ||
                                                                                           (Character.PositionComp.GetPosition() - MySector.MainCamera.Position).LengthSquared() < 100f))))
            {
                if (FinalThrust.LengthSquared() > 0.001f)
                {
                    Character.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, FinalThrust, null, null);
                }

                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;
                    }
                }
            }
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        protected override void UpdateThrusts(bool networkUpdate = false)
        {
            base.UpdateThrusts(networkUpdate);

            ProfilerShort.Begin("ThrusterBlockComponent.UpdateThrusts");
            if (CubeGrid != null && CubeGrid.Physics != null)
            {
                if (CubeGrid.Physics.Enabled)
                {
                    if (FinalThrust.LengthSquared() > 0.001f)
                    {
                        var thrust = FinalThrust;
                        if (CubeGrid.Physics.IsWelded) //only reliable variant
                        {
                            thrust = Vector3.TransformNormal(thrust, CubeGrid.WorldMatrix);
                            thrust = Vector3.TransformNormal(thrust, Matrix.Invert(CubeGrid.Physics.RigidBody.GetRigidBodyMatrix()));
                        }
                        CubeGrid.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, thrust, null, null);

                        if (MyPerGameSettings.EnableMultiplayerVelocityCompensation)
                        {
                            Vector3 velocity = CubeGrid.Physics.LinearVelocity;
                            float   maxSpeed = CubeGrid.GridSizeEnum == MyCubeSize.Large ? MyGridPhysics.LargeShipMaxLinearVelocity() : MyGridPhysics.SmallShipMaxLinearVelocity();

                            maxSpeed *= Sync.RelativeSimulationRatio;
                            if (velocity.LengthSquared() > maxSpeed * maxSpeed)
                            {
                                velocity.Normalize();
                                velocity *= maxSpeed;
                                CubeGrid.Physics.LinearVelocity = velocity;
                            }
                        }
                    }

                    const float stoppingVelocitySq = 0.001f * 0.001f;
                    if (CubeGrid.Physics.LinearVelocity != Vector3.Zero && CubeGrid.Physics.LinearVelocity.LengthSquared() < stoppingVelocitySq && CubeGrid.Physics.RigidBody.IsActive)
                    {
                        CubeGrid.Physics.LinearVelocity = Vector3.Zero;
                        ControlThrustChanged            = true;
                    }
                }
            }
            ProfilerShort.End();
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
        }