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;
                if (m_rotorGrid.Physics == null)
                {
                    return(false);
                }
                var rotorBody = m_rotorGrid.Physics.RigidBody;
                var data      = new HkLimitedHingeConstraintData();
                m_motor = new HkVelocityConstraintMotor(1.0f, 1000000f);

                data.SetSolvingMethod(HkSolvingMethod.MethodStabilized);
                data.Motor = m_motor;
                data.DisableLimits();

                var posA      = DummyPosition;
                var posB      = rotor.Position * rotor.CubeGrid.GridSize;
                var axisA     = PositionComp.LocalMatrix.Up;
                var axisAPerp = PositionComp.LocalMatrix.Forward;
                var axisB     = rotor.PositionComp.LocalMatrix.Up;
                var axisBPerp = rotor.PositionComp.LocalMatrix.Forward;
                data.SetInBodySpace(ref posA, ref posB, ref axisA, ref axisB, ref axisAPerp, ref axisBPerp);
                m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, rotorBody, data);

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

                SetAngleToPhysics();

                m_rotorBlock.Attach(this);

                if (updateGroup)
                {
                    OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid);
                    OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid);
                }
                m_isAttached = true;
                return(true);
            }

            return(false);
        }
Beispiel #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);
        }
        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;
        }
        public override bool Attach(MyMotorRotor rotor, bool updateGroup = true)
        {
            Debug.Assert(rotor != null, "Rotor cannot be null!");
            Debug.Assert(m_constraint == null, "Already attached, call detach first!");
            Debug.Assert(m_rotorBlockId.Value.OtherEntityId == rotor.EntityId, "m_rotorBlockId must be set prior calling Attach");

            if (CubeGrid.Physics != null && CubeGrid.Physics.Enabled)
            {
                m_rotorBlock = rotor;
                m_rotorGrid  = m_rotorBlock.CubeGrid;
                var rotorBody = m_rotorGrid.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.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(Sync.RelativeSimulationRatio * m_damping);
                data.SetSuspensionStrength(Sync.RelativeSimulationRatio * 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_rotorBlock.Attach(this);
                PropagateFriction(m_friction);
                UpdateIsWorking();

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

                return(true);
            }

            return(false);
        }
        public override bool Attach(MyMotorRotor rotor, bool updateGroup = true)
        {
            Debug.Assert(rotor != null, "Rotor cannot be null!");
            Debug.Assert(m_constraint == null, "Already attached, call detach first!");
            Debug.Assert(m_rotorBlockId.Value.OtherEntityId == 0 || m_rotorBlockId.Value.OtherEntityId == rotor.EntityId, "m_rotorBlockId must be set prior calling Attach");

            if (rotor == null || rotor.CubeGrid == null || MarkedForClose || Closed || CubeGrid.MarkedForClose || CubeGrid.Closed || rotor.MarkedForClose || rotor.Closed ||
                rotor.CubeGrid.MarkedForClose || rotor.CubeGrid.Closed)
            {
                return(false);
            }

            if (CubeGrid.Physics != null && CubeGrid.Physics.Enabled)
            {
                m_rotorBlock = rotor;
                m_rotorGrid  = m_rotorBlock.CubeGrid;
                if (m_rotorGrid.Physics == null)
                {
                    return(false);
                }
                if (CubeGrid.Physics.RigidBody == m_rotorGrid.Physics.RigidBody)
                {
                    if (updateGroup && m_welded)
                    {
                        OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid);
                        OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid);
                    }
                    m_isAttached = true;
                    return(true);
                }
                var rotorBody = m_rotorGrid.Physics.RigidBody;
                var data      = new HkLimitedHingeConstraintData();
                m_motor = new HkVelocityConstraintMotor(1.0f, 1000000f);

                data.SetSolvingMethod(HkSolvingMethod.MethodStabilized);
                data.Motor = m_motor;
                data.DisableLimits();

                var posA      = DummyPosition;
                var posB      = rotor.Position * rotor.CubeGrid.GridSize;
                var axisA     = PositionComp.LocalMatrix.Up;
                var axisAPerp = PositionComp.LocalMatrix.Forward;
                var axisB     = rotor.PositionComp.LocalMatrix.Up;
                var axisBPerp = rotor.PositionComp.LocalMatrix.Forward;
                data.SetInBodySpace(posA, posB, axisA, axisB, axisAPerp, axisBPerp, CubeGrid.Physics, m_rotorGrid.Physics);
                m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, rotorBody, data);

                m_constraint.WantRuntime = true;
                CubeGrid.Physics.AddConstraint(m_constraint);
                if (!m_constraint.InWorld)
                {
                    CubeGrid.Physics.RemoveConstraint(m_constraint);
                    m_constraint.Dispose();
                    m_constraint = null;
                    return(false);
                }
                m_constraint.Enabled = true;

                SetAngleToPhysics();

                m_rotorBlock.Attach(this);

                if (updateGroup)
                {
                    OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid);
                    OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid);
                    m_rotorGrid.OnPhysicsChanged += cubeGrid_OnPhysicsChanged;
                }
                m_isAttached = true;
                UpdateText();
                return(true);
            }

            return(false);
        }
        public override bool Attach(MyMotorRotor rotor, bool updateGroup = true)
        {
            Debug.Assert(rotor != null, "Rotor cannot be null!");
            Debug.Assert(m_constraint == null, "Already attached, call detach first!");
            Debug.Assert(m_rotorBlockId.Value.OtherEntityId == 0 || m_rotorBlockId.Value.OtherEntityId == rotor.EntityId, "m_rotorBlockId must be set prior calling Attach");

            if (rotor == null || MarkedForClose || Closed || rotor.MarkedForClose || rotor.Closed || CubeGrid.MarkedForClose || CubeGrid.Closed)
            {
                return false;
            }

            if (CubeGrid.Physics != null && CubeGrid.Physics.Enabled)
            {
                m_rotorBlock = rotor;
                m_rotorGrid = m_rotorBlock.CubeGrid;
                if (m_rotorGrid.Physics == null)
                    return false;
                if (CubeGrid.Physics.RigidBody == m_rotorGrid.Physics.RigidBody)
                {
                    if (updateGroup && m_welded)
                    {
                        OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid);
                        OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid);
                   }
                    m_isAttached = true;
                    return true;
                }
                var rotorBody = m_rotorGrid.Physics.RigidBody;
                var data = new HkLimitedHingeConstraintData();
                m_motor = new HkVelocityConstraintMotor(1.0f, 1000000f);

                data.SetSolvingMethod(HkSolvingMethod.MethodStabilized);
                data.Motor = m_motor;
                data.DisableLimits();

                var posA = DummyPosition;
                var posB = rotor.Position * rotor.CubeGrid.GridSize;
                var axisA = PositionComp.LocalMatrix.Up;
                var axisAPerp = PositionComp.LocalMatrix.Forward;
                var axisB = rotor.PositionComp.LocalMatrix.Up;
                var axisBPerp = rotor.PositionComp.LocalMatrix.Forward;
                data.SetInBodySpace(posA, posB, axisA, axisB, axisAPerp, axisBPerp, CubeGrid.Physics, m_rotorGrid.Physics);
                m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, rotorBody, data);

                m_constraint.WantRuntime = true;
                CubeGrid.Physics.AddConstraint(m_constraint);
                if(!m_constraint.InWorld)
                {
                    CubeGrid.Physics.RemoveConstraint(m_constraint);
                    m_constraint.Dispose();
                    m_constraint = null;
                    return false;
                }
                m_constraint.Enabled = true;

                SetAngleToPhysics();

                m_rotorBlock.Attach(this);

                if (updateGroup)
                {
                    OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid);
                    OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid);
                    m_rotorGrid.OnPhysicsChanged += cubeGrid_OnPhysicsChanged;
                }
                m_isAttached = true;
                UpdateText();
                return true;
            }

            return false;
        }
Beispiel #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);
        }
        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;
                if (m_rotorGrid.Physics == null)
                    return false;
                var rotorBody = m_rotorGrid.Physics.RigidBody;
                var data = new HkLimitedHingeConstraintData();
                m_motor = new HkVelocityConstraintMotor(1.0f, 1000000f);

                data.SetSolvingMethod(HkSolvingMethod.MethodStabilized);
                data.Motor = m_motor;
                data.DisableLimits();

                var posA = DummyPosition;
                var posB = rotor.Position * rotor.CubeGrid.GridSize;
                var axisA = PositionComp.LocalMatrix.Up;
                var axisAPerp = PositionComp.LocalMatrix.Forward;
                var axisB = rotor.PositionComp.LocalMatrix.Up;
                var axisBPerp = rotor.PositionComp.LocalMatrix.Forward;
                data.SetInBodySpace(ref posA, ref posB, ref axisA, ref axisB, ref axisAPerp, ref axisBPerp);
                m_constraint = new HkConstraint(CubeGrid.Physics.RigidBody, rotorBody, data);

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

                SetAngleToPhysics();

                m_rotorBlock.Attach(this);

                if (updateGroup)
                {
                    OnConstraintAdded(GridLinkTypeEnum.Physical, m_rotorGrid);
                    OnConstraintAdded(GridLinkTypeEnum.Logical, m_rotorGrid);
                }
                m_isAttached = true;
                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;
        }
        public override bool Attach(MyMotorRotor rotor, bool updateGroup = true)
        {
            Debug.Assert(rotor != null, "Rotor cannot be null!");
            Debug.Assert(m_constraint == null, "Already attached, call detach first!");
            Debug.Assert(m_rotorBlockId.Value.OtherEntityId == rotor.EntityId, "m_rotorBlockId must be set prior calling Attach");
            if (rotor == null || MarkedForClose || Closed || rotor.MarkedForClose || rotor.Closed || CubeGrid.MarkedForClose || CubeGrid.Closed)
            {
                return false;
            }
            if (CubeGrid.Physics != null && CubeGrid.Physics.Enabled)
            {
                m_rotorBlock = rotor;
                m_rotorGrid = m_rotorBlock.CubeGrid;
                var rotorBody = m_rotorGrid.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.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(Sync.RelativeSimulationRatio * m_damping);
                data.SetSuspensionStrength(Sync.RelativeSimulationRatio * 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_rotorBlock.Attach(this);
                PropagateFriction(m_friction);
                UpdateIsWorking();

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

                return true;
            }

            return false;
        }