Example #1
0
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();
            var lastSteer = m_steerAngle;
            var player    = Sync.Players.GetControllingPlayer(CubeGrid);

            if ((player != null && player.IsLocalPlayer) || (player == null && Sync.IsServer))
            {
                if (!m_wasSteering)
                {
                    if (Math.Abs(m_steerAngle) < 0.00001)
                    {
                        m_steerAngle.Value = 0;
                    }
                    if (m_steerAngle != 0 && SteerReturnSpeed > 0)
                    {
                        m_steerAngle.Value = (m_steerAngle > 0 ? Math.Max(m_steerAngle - SteerReturnSpeed, 0) : Math.Min(m_steerAngle + SteerReturnSpeed, 0));
                    }
                }
            }

            m_wasSteering = false;

            if (SafeConstraint != null)
            {
                HkWheelConstraintData constraint = (m_constraint.ConstraintData as HkWheelConstraintData);
                if (Steering)
                {
                    constraint.SetSteeringAngle(m_steerAngle);
                }
            }

            UpdateSoundState();
            m_wasAccelerating = false;
        }
Example #2
0
        public override bool Attach(MyMotorRotor rotor, bool updateSync = false, bool updateGroup = true)
        {
            if (CubeGrid.Physics == null || SafeConstraint != null)
            {
                return(false);
            }

            Debug.Assert(SafeConstraint == null);

            if (CubeGrid.Physics.Enabled && rotor != null)
            {
                m_rotorBlock   = rotor;
                m_rotorBlockId = rotor.EntityId;

                if (updateSync)
                {
                    SyncObject.AttachRotor(m_rotorBlock);
                }

                m_rotorGrid = m_rotorBlock.CubeGrid;
                var rotorBody = m_rotorGrid.Physics.RigidBody;
                HkWheelConstraintData data = new HkWheelConstraintData();
                var suspensionAx           = PositionComp.LocalMatrix.Forward;
                var posA      = DummyPosition + (suspensionAx * m_height);
                var posB      = rotor.DummyPosLoc;
                var axisA     = PositionComp.LocalMatrix.Up;
                var axisAPerp = PositionComp.LocalMatrix.Forward;
                var axisB     = rotor.PositionComp.LocalMatrix.Up;
                //empirical values because who knows what havoc sees behind this
                //docs say one value should mean same effect for 2 ton or 200 ton vehicle
                //but we have virtual mass blocks so real mass doesnt corespond to actual "weight" in game and varying gravity
                data.SetSuspensionDamping(Damping);
                data.SetSuspensionStrength(Strength);
                //Min/MaxHeight also define the limits of the suspension and SuspensionTravel lowers this limit
                data.SetSuspensionMinLimit((BlockDefinition.MinHeight - m_height) * SuspensionTravel);
                data.SetSuspensionMaxLimit((BlockDefinition.MaxHeight - m_height) * SuspensionTravel);
                data.SetInBodySpace(ref posB, ref posA, ref axisB, ref axisA, ref suspensionAx, ref suspensionAx);
                m_constraint = new HkConstraint(rotorBody, CubeGrid.Physics.RigidBody, data);

                m_constraint.WantRuntime = true;
                CubeGrid.Physics.AddConstraint(m_constraint);
                m_constraint.Enabled = true;

                m_rotorBlock.Attach(this);
                UpdateIsWorking();

                if (updateGroup)
                {
                    OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid);
                    OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid);
                }

                return(true);
            }

            return(false);
        }
Example #3
0
        protected override bool CreateConstraint(MyAttachableTopBlockBase rotor)
        {
            if (!base.CreateConstraint(rotor))
            {
                return(false);
            }
            var rotorBody = TopGrid.Physics.RigidBody;

            rotorBody.MaxAngularVelocity = float.MaxValue;
            rotorBody.Restitution        = 0.5f;
            CubeGrid.GetPhysicsBody().HavokWorld.BreakOffPartsUtil.UnmarkEntityBreakable(rotorBody);
            if (MyFakes.WHEEL_SOFTNESS)
            {
                HkUtils.SetSoftContact(rotorBody, null, MyPhysicsConfig.WheelSoftnessRatio,
                                       MyPhysicsConfig.WheelSoftnessVelocity);
            }
            var info = HkGroupFilter.CalcFilterInfo(rotorBody.Layer,
                                                    CubeGrid.GetPhysicsBody().HavokCollisionSystemID, 1, 1);

            rotorBody.SetCollisionFilterInfo(info);
            CubeGrid.GetPhysicsBody().HavokWorld.RefreshCollisionFilterOnEntity(rotorBody);
            HkWheelConstraintData data = new HkWheelConstraintData();
            var suspensionAx           = PositionComp.LocalMatrix.Forward;
            var posA      = DummyPosition + (suspensionAx * m_height);
            var posB      = (rotor as MyMotorRotor).DummyPosLoc;
            var axisA     = PositionComp.LocalMatrix.Up;
            var axisAPerp = PositionComp.LocalMatrix.Forward;
            var axisB     = rotor.PositionComp.LocalMatrix.Up;

            data.SetInBodySpace(posB, posA, axisB, axisA, suspensionAx, suspensionAx, RotorGrid.Physics,
                                CubeGrid.Physics);
            //empirical values because who knows what havoc sees behind this
            //docs say one value should mean same effect for 2 ton or 200 ton vehicle
            //but we have virtual mass blocks so real mass doesnt corespond to actual "weight" in game and varying gravity
            data.SetSuspensionDamping(m_damping);
            data.SetSuspensionStrength(m_strenth);
            //Min/MaxHeight also define the limits of the suspension and SuspensionTravel lowers this limit
            data.SetSuspensionMinLimit((BlockDefinition.MinHeight - m_height) * SuspensionTravel);
            data.SetSuspensionMaxLimit((BlockDefinition.MaxHeight - m_height) * SuspensionTravel);
            m_constraint = new HkConstraint(rotorBody, CubeGrid.Physics.RigidBody, data);

            m_constraint.WantRuntime = true;
            CubeGrid.Physics.AddConstraint(m_constraint);
            if (!m_constraint.InWorld)
            {
                Debug.Fail("Constraint not added!");
                CubeGrid.Physics.RemoveConstraint(m_constraint);
                m_constraint = null;
                return(false);
            }
            m_constraint.Enabled = true;
            return(true);
        }
 public static void SetInBodySpace(this HkWheelConstraintData data, Vector3 posA, Vector3 posB, Vector3 axisA, Vector3 axisB, Vector3 suspension, Vector3 steering, MyPhysicsBody bodyA, MyPhysicsBody bodyB)
 {
     if (bodyA.IsWelded)
     {
         posA  = Vector3.Transform(posA, bodyA.WeldInfo.Transform);
         axisA = Vector3.TransformNormal(axisA, bodyA.WeldInfo.Transform);
     }
     if (bodyB.IsWelded)
     {
         posB       = Vector3.Transform(posB, bodyB.WeldInfo.Transform);
         axisB      = Vector3.TransformNormal(axisB, bodyB.WeldInfo.Transform);
         suspension = Vector3.TransformNormal(suspension, bodyB.WeldInfo.Transform);
         steering   = Vector3.TransformNormal(steering, bodyB.WeldInfo.Transform);
     }
     data.SetInBodySpaceInternal(ref posA, ref posB, ref axisA, ref axisB, ref suspension, ref steering);
 }
Example #5
0
        protected override bool Attach(MyAttachableTopBlockBase rotor, bool updateGroup = true)
        {
            Debug.Assert(rotor != null, "Rotor cannot be null!");
            Debug.Assert(m_constraint == null, "Already attached, call detach first!");


            if (rotor is MyMotorRotor)
            {
                if (CubeGrid.Physics != null && CubeGrid.Physics.Enabled)
                {
                    m_topBlock = rotor;
                    m_topGrid  = m_topBlock.CubeGrid;
                    var rotorBody = m_topGrid.Physics.RigidBody;
                    rotorBody.MaxAngularVelocity = float.MaxValue;
                    rotorBody.Restitution        = 0.5f;
                    CubeGrid.GetPhysicsBody().HavokWorld.BreakOffPartsUtil.UnmarkEntityBreakable(rotorBody);
                    if (MyFakes.WHEEL_SOFTNESS)
                    {
                        HkUtils.SetSoftContact(rotorBody, null, MyPhysicsConfig.WheelSoftnessRatio, MyPhysicsConfig.WheelSoftnessVelocity);
                    }
                    var info = HkGroupFilter.CalcFilterInfo(rotorBody.Layer, CubeGrid.GetPhysicsBody().HavokCollisionSystemID, 1, 1);
                    rotorBody.SetCollisionFilterInfo(info);
                    HkWheelConstraintData data = new HkWheelConstraintData();
                    var suspensionAx           = PositionComp.LocalMatrix.Forward;
                    var posA      = DummyPosition + (suspensionAx * m_height);
                    var posB      = (rotor as MyMotorRotor).DummyPosLoc;
                    var axisA     = PositionComp.LocalMatrix.Up;
                    var axisAPerp = PositionComp.LocalMatrix.Forward;
                    var axisB     = rotor.PositionComp.LocalMatrix.Up;
                    //empirical values because who knows what havoc sees behind this
                    //docs say one value should mean same effect for 2 ton or 200 ton vehicle
                    //but we have virtual mass blocks so real mass doesnt corespond to actual "weight" in game and varying gravity
                    data.SetSuspensionDamping(m_damping);
                    data.SetSuspensionStrength(m_strenth);
                    //Min/MaxHeight also define the limits of the suspension and SuspensionTravel lowers this limit
                    data.SetSuspensionMinLimit((BlockDefinition.MinHeight - m_height) * SuspensionTravel);
                    data.SetSuspensionMaxLimit((BlockDefinition.MaxHeight - m_height) * SuspensionTravel);
                    data.SetInBodySpace(posB, posA, axisB, axisA, suspensionAx, suspensionAx, RotorGrid.Physics, CubeGrid.Physics);
                    m_constraint = new HkConstraint(rotorBody, CubeGrid.Physics.RigidBody, data);

                    m_constraint.WantRuntime = true;
                    CubeGrid.Physics.AddConstraint(m_constraint);
                    if (!m_constraint.InWorld)
                    {
                        Debug.Fail("Constraint not added!");
                        CubeGrid.Physics.RemoveConstraint(m_constraint);
                        m_constraint = null;
                        return(false);
                    }
                    m_constraint.Enabled = true;

                    m_topBlock.Attach(this);
                    m_isAttached = true;
                    PropagateFriction(m_friction);
                    UpdateIsWorking();

                    if (m_updateBrakeNeeded)
                    {
                        UpdateBrake();
                    }
                    if (m_updateFrictionNeeded)
                    {
                        FrictionChanged();
                    }


                    if (updateGroup)
                    {
                        OnConstraintAdded(GridLinkTypeEnum.Physical, m_topGrid);
                        OnConstraintAdded(GridLinkTypeEnum.Logical, m_topGrid);
                    }

                    return(true);
                }
            }
            return(false);
        }
        public override bool Attach(MyMotorRotor rotor, bool updateSync = false, bool updateGroup = true)
        {
            if (CubeGrid.Physics == null || SafeConstraint != null)
                return false;

            Debug.Assert(SafeConstraint == null);

            if (CubeGrid.Physics.Enabled && rotor != null)
            {
                m_rotorBlock = rotor;
                m_rotorBlockId = rotor.EntityId;

                if (updateSync)
                    SyncObject.AttachRotor(m_rotorBlock);

                m_rotorGrid = m_rotorBlock.CubeGrid;
                var rotorBody = m_rotorGrid.Physics.RigidBody;
                HkWheelConstraintData data = new HkWheelConstraintData();
                var posA = DummyPosition;
                var posB = rotor.DummyPosLoc;
                var axisA = PositionComp.LocalMatrix.Up;
                var axisAPerp = PositionComp.LocalMatrix.Forward;
                var axisB = rotor.PositionComp.LocalMatrix.Up;
                var suspensionAx = PositionComp.LocalMatrix.Forward;
                //empirical values because who knows what havoc sees behind this 
                //docs say one value should mean same effect for 2 ton or 200 ton vehicle 
                //but we have virtual mass blocks so real mass doesnt corespond to actual "weight" in game and varying gravity
                data.SetSuspensionDamping(Damping);
                data.SetSuspensionStrength(Strength);
                data.SetSuspensionMaxLimit(BlockDefinition.SuspensionLimit);
                data.SetSuspensionMinLimit(-BlockDefinition.SuspensionLimit);
                data.SetInBodySpace(ref posB, ref posA, ref axisB, ref axisA, ref suspensionAx, ref suspensionAx);
                m_constraint = new HkConstraint(rotorBody, CubeGrid.Physics.RigidBody, data);

                m_constraint.WantRuntime = true;
                CubeGrid.Physics.AddConstraint(m_constraint);
                m_constraint.Enabled = true;

                m_rotorBlock.Attach(this);
                UpdateIsWorking();

                if (updateGroup)
                {
                    OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid);
                    OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid);
                }

                return true;
            }

            return false;
        }
Example #7
0
        public override bool Attach(MyMotorRotor rotor, bool updateSync = false, bool updateGroup = true)
        {
            if (CubeGrid.Physics == null || SafeConstraint != null)
            {
                return(false);
            }

            Debug.Assert(SafeConstraint == null);

            if (CubeGrid.Physics.Enabled && rotor != null)
            {
                m_rotorBlock   = rotor;
                m_rotorBlockId = rotor.EntityId;

                if (updateSync)
                {
                    SyncObject.AttachRotor(m_rotorBlock);
                }

                m_rotorGrid = m_rotorBlock.CubeGrid;
                var rotorBody = m_rotorGrid.Physics.RigidBody;
                rotorBody.MaxAngularVelocity = float.MaxValue;
                rotorBody.AngularDamping    *= 4;
                if (MyFakes.WHEEL_SOFTNESS)
                {
                    HkUtils.SetSoftContact(rotorBody, null, MyPhysicsConfig.WheelSoftnessRatio, MyPhysicsConfig.WheelSoftnessVelocity);
                }
                var info = HkGroupFilter.CalcFilterInfo(rotorBody.Layer, CubeGrid.Physics.HavokCollisionSystemID, 1, 1);
                rotorBody.SetCollisionFilterInfo(info);
                HkWheelConstraintData data = new HkWheelConstraintData();
                var suspensionAx           = PositionComp.LocalMatrix.Forward;
                var posA      = DummyPosition + (suspensionAx * m_height);
                var posB      = rotor.DummyPosLoc;
                var axisA     = PositionComp.LocalMatrix.Up;
                var axisAPerp = PositionComp.LocalMatrix.Forward;
                var axisB     = rotor.PositionComp.LocalMatrix.Up;
                //empirical values because who knows what havoc sees behind this
                //docs say one value should mean same effect for 2 ton or 200 ton vehicle
                //but we have virtual mass blocks so real mass doesnt corespond to actual "weight" in game and varying gravity
                data.SetSuspensionDamping(Damping);
                data.SetSuspensionStrength(Strength);
                //Min/MaxHeight also define the limits of the suspension and SuspensionTravel lowers this limit
                data.SetSuspensionMinLimit((BlockDefinition.MinHeight - m_height) * SuspensionTravel);
                data.SetSuspensionMaxLimit((BlockDefinition.MaxHeight - m_height) * SuspensionTravel);
                data.SetInBodySpace(posB, posA, axisB, axisA, suspensionAx, suspensionAx, RotorGrid.Physics, CubeGrid.Physics);
                m_constraint = new HkConstraint(rotorBody, CubeGrid.Physics.RigidBody, data);

                m_constraint.WantRuntime = true;
                CubeGrid.Physics.AddConstraint(m_constraint);
                m_constraint.Enabled = true;

                m_rotorBlock.Attach(this);
                PropagateFriction(m_friction);
                UpdateIsWorking();

                if (updateGroup)
                {
                    OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid);
                    OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid);
                }

                return(true);
            }

            return(false);
        }
        protected override bool Attach(MyAttachableTopBlockBase rotor, bool updateGroup = true)
        {
            Debug.Assert(rotor != null, "Rotor cannot be null!");
            Debug.Assert(m_constraint == null, "Already attached, call detach first!");


            if (rotor is MyMotorRotor)
            {
                if (CubeGrid.Physics != null && CubeGrid.Physics.Enabled)
                {
                    m_topBlock = rotor;
                    m_topGrid = m_topBlock.CubeGrid;
                    var rotorBody = m_topGrid.Physics.RigidBody;
                    rotorBody.MaxAngularVelocity = float.MaxValue;
                    rotorBody.Restitution = 0.5f;
                    CubeGrid.GetPhysicsBody().HavokWorld.BreakOffPartsUtil.UnmarkEntityBreakable(rotorBody);
                    if (MyFakes.WHEEL_SOFTNESS)
                    {
                        HkUtils.SetSoftContact(rotorBody, null, MyPhysicsConfig.WheelSoftnessRatio, MyPhysicsConfig.WheelSoftnessVelocity);
                    }
                    var info = HkGroupFilter.CalcFilterInfo(rotorBody.Layer, CubeGrid.GetPhysicsBody().HavokCollisionSystemID, 1, 1);
                    rotorBody.SetCollisionFilterInfo(info);
                    HkWheelConstraintData data = new HkWheelConstraintData();
                    var suspensionAx = PositionComp.LocalMatrix.Forward;
                    var posA = DummyPosition + (suspensionAx * m_height);
                    var posB = (rotor as MyMotorRotor).DummyPosLoc;
                    var axisA = PositionComp.LocalMatrix.Up;
                    var axisAPerp = PositionComp.LocalMatrix.Forward;
                    var axisB = rotor.PositionComp.LocalMatrix.Up;
                    //empirical values because who knows what havoc sees behind this 
                    //docs say one value should mean same effect for 2 ton or 200 ton vehicle 
                    //but we have virtual mass blocks so real mass doesnt corespond to actual "weight" in game and varying gravity
                    data.SetSuspensionDamping(m_damping);
                    data.SetSuspensionStrength(m_strenth);
                    //Min/MaxHeight also define the limits of the suspension and SuspensionTravel lowers this limit
                    data.SetSuspensionMinLimit((BlockDefinition.MinHeight - m_height) * SuspensionTravel);
                    data.SetSuspensionMaxLimit((BlockDefinition.MaxHeight - m_height) * SuspensionTravel);
                    data.SetInBodySpace(posB, posA, axisB, axisA, suspensionAx, suspensionAx, RotorGrid.Physics, CubeGrid.Physics);
                    m_constraint = new HkConstraint(rotorBody, CubeGrid.Physics.RigidBody, data);

                    m_constraint.WantRuntime = true;
                    CubeGrid.Physics.AddConstraint(m_constraint);
                    if (!m_constraint.InWorld)
                    {
                        Debug.Fail("Constraint not added!");
                        CubeGrid.Physics.RemoveConstraint(m_constraint);
                        m_constraint = null;
                        return false;
                    }
                    m_constraint.Enabled = true;

                    m_topBlock.Attach(this);
                    m_isAttached = true;
                    PropagateFriction(m_friction);
                    UpdateIsWorking();

                    if (m_updateBrakeNeeded)
                    {
                        UpdateBrake();
                    }
                    if (m_updateFrictionNeeded)
                    {
                        FrictionChanged();
                    }


                    if (updateGroup)
                    {
                        OnConstraintAdded(GridLinkTypeEnum.Physical, m_topGrid);
                        OnConstraintAdded(GridLinkTypeEnum.Logical, m_topGrid);
                    }

                    return true;
                }
            }
            return false;
        }
        public override bool Attach(MyMotorRotor rotor, bool updateSync = false, bool updateGroup = true)
        {
            if (CubeGrid.Physics == null || SafeConstraint != null)
                return false;

            Debug.Assert(SafeConstraint == null);

            if (CubeGrid.Physics.Enabled && rotor != null)
            {
                m_rotorBlock = rotor;
                m_rotorBlockId = rotor.EntityId;

                if (updateSync)
                    SyncObject.AttachRotor(m_rotorBlock);

                m_rotorGrid = m_rotorBlock.CubeGrid;
                var rotorBody = m_rotorGrid.Physics.RigidBody;
                rotorBody.MaxAngularVelocity = float.MaxValue;
                rotorBody.AngularDamping *= 4;
                if (MyFakes.WHEEL_SOFTNESS)
                {
                    HkUtils.SetSoftContact(rotorBody, null, MyPhysicsConfig.WheelSoftnessRatio, MyPhysicsConfig.WheelSoftnessVelocity);
                }
                var info = HkGroupFilter.CalcFilterInfo(rotorBody.Layer, CubeGrid.Physics.HavokCollisionSystemID, 1, 1);
                rotorBody.SetCollisionFilterInfo(info);
                HkWheelConstraintData data = new HkWheelConstraintData();
                var suspensionAx = PositionComp.LocalMatrix.Forward;
                var posA = DummyPosition + (suspensionAx * m_height);
                var posB = rotor.DummyPosLoc;
                var axisA = PositionComp.LocalMatrix.Up;
                var axisAPerp = PositionComp.LocalMatrix.Forward;
                var axisB = rotor.PositionComp.LocalMatrix.Up;
                //empirical values because who knows what havoc sees behind this 
                //docs say one value should mean same effect for 2 ton or 200 ton vehicle 
                //but we have virtual mass blocks so real mass doesnt corespond to actual "weight" in game and varying gravity
                data.SetSuspensionDamping(Damping);
                data.SetSuspensionStrength(Strength);
                //Min/MaxHeight also define the limits of the suspension and SuspensionTravel lowers this limit
                data.SetSuspensionMinLimit((BlockDefinition.MinHeight - m_height) * SuspensionTravel);
                data.SetSuspensionMaxLimit((BlockDefinition.MaxHeight - m_height) * SuspensionTravel);
                data.SetInBodySpace( posB,  posA,  axisB,  axisA,  suspensionAx,  suspensionAx, RotorGrid.Physics, CubeGrid.Physics);
                m_constraint = new HkConstraint(rotorBody, CubeGrid.Physics.RigidBody, data);

                m_constraint.WantRuntime = true;
                CubeGrid.Physics.AddConstraint(m_constraint);
                m_constraint.Enabled = true;

                m_rotorBlock.Attach(this);
                PropagateFriction(m_friction);
                UpdateIsWorking();

                if (updateGroup)
                {
                    OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid);
                    OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid);
                }

                return true;
            }

            return false;
        }