Ejemplo n.º 1
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary>
        protected override void OnPostCreate(bool loaded)
        {
            base.OnPostCreate(loaded);

            if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle())
            {
                const string        regionTypeName = "ManualInfluenceRegion";
                InfluenceRegionType regionType     = (InfluenceRegionType)EntityTypes.Instance.GetByName(
                    regionTypeName);
                if (regionType == null)
                {
                    regionType = (InfluenceRegionType)EntityTypes.Instance.ManualCreateType(
                        regionTypeName,
                        EntityTypes.Instance.GetClassInfoByEntityClassName("InfluenceRegion"));
                    regionType.NetworkType = EntityNetworkTypes.ServerOnly;
                }

                region                  = (InfluenceRegion)Entities.Instance.Create(regionType, Map.Instance);
                region.ShapeType        = Region.ShapeTypes.Capsule;
                region.DistanceFunction = InfluenceRegion.DistanceFunctionType.NormalFadeAxisX;

                region.SetTransform(Position, Rotation, InfluenceRegionScale);
                region.PostCreate();
                region.AllowSave        = false;
                region.EditorSelectable = false;

                bladesMotor = PhysicsModel.GetMotor("bladesMotor") as GearedMotor;
            }

            SubscribeToTickEvent();
        }
Ejemplo n.º 2
0
        private void MohiOff()
        {
            //turning off some stuff when you are getting out of helli
            GearedMotor main = PhysicsModel.GetMotor("hellimain") as GearedMotor;
            GearedMotor back = PhysicsModel.GetMotor("helliback") as GearedMotor;

            main.Enabled = false;
            back.Enabled = false;

            if (rotorSoundChannel != null)
            {
                rotorSoundChannel.Stop();
                rotorSoundChannel = null;
            }
        }
Ejemplo n.º 3
0
        void TickIntellect()
        {
            //horizontalMotor
            {
                float throttle = 0;
                throttle += Intellect.GetControlKeyStrength(GameControlKeys.Left);
                throttle -= Intellect.GetControlKeyStrength(GameControlKeys.Right);

                GearedMotor motor = PhysicsModel.GetMotor("horizontalMotor") as GearedMotor;
                if (motor != null)
                {
                    motor.Throttle = throttle;
                }
            }

            //gibbetMotor
            {
                ServoMotor motor = PhysicsModel.GetMotor("gibbetMotor") as ServoMotor;
                if (motor != null)
                {
                    Radian needAngle = motor.DesiredAngle;

                    needAngle += Intellect.GetControlKeyStrength(GameControlKeys.Forward) * .004f;
                    needAngle -= Intellect.GetControlKeyStrength(GameControlKeys.Backward) * .004f;

                    MathFunctions.Clamp(ref needAngle,
                                        new Degree(-20.0f).InRadians(), new Degree(40.0f).InRadians());

                    motor.DesiredAngle = needAngle;
                }
            }

            //Change player LookDirection at rotation
            PlayerIntellect intellect = Intellect as PlayerIntellect;

            if (intellect != null)
            {
                Vec3 lookVector = intellect.LookDirection.GetVector();
                lookVector *= OldRotation.GetInverse();
                lookVector *= Rotation;
                intellect.LookDirection = SphereDir.FromVector(lookVector);
            }
        }
Ejemplo n.º 4
0
        private void TickChassis()
        {
            bool onGround = leftTrack.onGround || rightTrack.onGround;

            OnGround = onGround;
            float leftTrackThrottle  = 0;
            float rightTrackThrottle = 0;

            if (Intellect != null)
            {
                Reset(false);
                Wheels();
                ShiftBooster();
                GearchangeDtime();

                //force for stability
                float speedkmph = GetRealSpeed() * 3;
                float speedpure = speedkmph - (speedkmph % 1);

                MapObjectAttachedBillboard ta1 = GetFirstAttachedObjectByAlias("tail1")
                                                 as MapObjectAttachedBillboard;

                MapObjectAttachedBillboard ta2 = GetFirstAttachedObjectByAlias("tail2")
                                                 as MapObjectAttachedBillboard;

                MapObjectAttachedBillboard ta3 = GetFirstAttachedObjectByAlias("tail3")
                                                 as MapObjectAttachedBillboard;

                MapObjectAttachedBillboard ta4 = GetFirstAttachedObjectByAlias("tail4")
                                                 as MapObjectAttachedBillboard;

                bool backlightred = false;
                bool backlightw   = false;

                {
                    ServoMotor THREF = PhysicsModel.GetMotor("FB") as ServoMotor;
                    Radian     FB    = 0;

                    float forward = Intellect.GetControlKeyStrength(GameControlKeys.Forward);
                    leftTrackThrottle  += forward;
                    rightTrackThrottle += forward;

                    float backward = Intellect.GetControlKeyStrength(GameControlKeys.Backward);
                    leftTrackThrottle  -= backward;
                    rightTrackThrottle -= backward;

                    if (Intellect.IsControlKeyPressed(GameControlKeys.Forward))
                    {
                        if (GetRealSpeed() < 0.01)
                        {
                            backlightred = true;
                        }
                        FB++;
                    }
                    else if (Intellect.IsControlKeyPressed(GameControlKeys.Backward))
                    {
                        FB--;
                        if (GetRealSpeed() > 0.5)
                        {
                            backlightred = true;
                        }
                        if (GetRealSpeed() < 0.01)
                        {
                            backlightw = true;
                        }
                    }

                    MathFunctions.Clamp(ref FB,
                                        new Degree(-1.0f).InRadians(), new Degree(1.0f).InRadians());

                    THREF.DesiredAngle = FB;
                    if (ta1 != null)
                    {
                        ta1.Visible = backlightred;
                        ta2.Visible = backlightred;
                        ta3.Visible = backlightw;
                        ta4.Visible = backlightw;
                    }
                }
                {
                    ServoMotor wmotor   = PhysicsModel.GetMotor("wheel") as ServoMotor;
                    ServoMotor wmotor_2 = PhysicsModel.GetMotor("wheel2") as ServoMotor;

                    Radian needAngle = wmotor.DesiredAngle;

                    float left  = Intellect.GetControlKeyStrength(GameControlKeys.Left);
                    float right = Intellect.GetControlKeyStrength(GameControlKeys.Right);

                    if (left > 0)
                    {
                        needAngle -= 0.06f;
                    }
                    else if (right > 0)
                    {
                        needAngle += 0.06f;
                    }
                    else
                    {
                        needAngle = 0f;
                    }

                    float TBaseForce = 0;
                    float Pspeed     = GetRealSpeed();
                    if (Pspeed < 0)
                    {
                        Pspeed = -Pspeed;
                    }
                    TBaseForce = left + (-right);

                    float speedcoef = 1;
                    if (GetRealSpeed() < 10 && GetRealSpeed() > -10)
                    {
                        speedcoef = GetRealSpeed() / 10;
                    }

                    if (speedcoef < 0)
                    {
                        speedcoef = -speedcoef;
                    }

                    if (!Intellect.IsControlKeyPressed(GameControlKeys.Forward) && !Intellect.IsControlKeyPressed(GameControlKeys.Backward) && speedcoef != 1)
                    {
                        TBaseForce = TBaseForce * 1.5f;
                    }

                    if (GetRealSpeed() < 0)
                    {
                        TBaseForce = -TBaseForce;
                    }

                    float SpeedD = 120 / GetRealSpeed();
                    MathFunctions.Clamp(ref SpeedD, 1, 1.6f);
                    float TMainForce = TBaseForce * chassisBody.Mass * SpeedD * 10;

                    if (OnGround)
                    {
                        chassisBody.AddForce(ForceType.LocalTorque, TickDelta,
                                             new Vec3(0, 0, TMainForce * speedcoef * 2), Vec3.Zero);
                    }

                    MathFunctions.Clamp(ref needAngle,
                                        new Degree(-29.0f).InRadians(), new Degree(29.0f).InRadians());

                    if (wmotor != null)
                    {
                        wmotor.DesiredAngle   = needAngle;
                        wmotor_2.DesiredAngle = needAngle;
                    }
                }
            }

            Vec3 localLinearVelocity = chassisBody.LinearVelocity * chassisBody.Rotation.GetInverse();

            //add drive force

            float slopeForwardForceCoeffient;
            float slopeBackwardForceCoeffient;
            float slopeLinearDampingAddition;

            {
                Vec3   dir        = chassisBody.Rotation.GetForward();
                Radian slopeAngle = MathFunctions.ATan(dir.Z, dir.ToVec2().Length());
                Radian maxAngle   = MathFunctions.PI / 4;//new Degree(45)

                slopeForwardForceCoeffient = 1;
                if (slopeAngle > maxAngle)
                {
                    slopeForwardForceCoeffient = 0;
                }

                slopeBackwardForceCoeffient = 1;
                if (slopeAngle < -maxAngle)
                {
                    slopeBackwardForceCoeffient = 0;
                }

                MathFunctions.Clamp(ref slopeForwardForceCoeffient, 0, 1);
                MathFunctions.Clamp(ref slopeBackwardForceCoeffient, 0, 1);

                slopeLinearDampingAddition = localLinearVelocity.X > 0 ? slopeAngle : -slopeAngle;
                //slopeLinearDampingAddition *= 1;
                if (slopeLinearDampingAddition < 0)
                {
                    slopeLinearDampingAddition = 0;
                }
            }

            if (leftTrack.onGround)
            {
                if (leftTrackThrottle > 0 && localLinearVelocity.X < Type.MaxForwardSpeed)
                {
                    float force = localLinearVelocity.X > 0 ? currentGear.GearDriveForwardForce + NOSBoost + DownPower : currentGear.GearBrakeForce;
                    force *= leftTrackThrottle;
                    force *= slopeForwardForceCoeffient;
                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, tracksPositionYOffset, 0));
                }

                if (leftTrackThrottle < 0 && (-localLinearVelocity.X) < Type.MaxBackwardSpeed)
                {
                    float force = currentGear.GearBrakeForce; //: Type.DriveBackwardForce;
                    force *= leftTrackThrottle;
                    force *= slopeBackwardForceCoeffient;
                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, tracksPositionYOffset, 0));
                }
            }

            if (rightTrack.onGround)
            {
                if (rightTrackThrottle > 0 && localLinearVelocity.X < Type.MaxForwardSpeed)
                {
                    float force = localLinearVelocity.X > 0 ? currentGear.GearDriveForwardForce + NOSBoost + DownPower : currentGear.GearBrakeForce;
                    force *= rightTrackThrottle;
                    force *= slopeForwardForceCoeffient;
                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, -tracksPositionYOffset, 0));
                }

                if (rightTrackThrottle < 0 && (-localLinearVelocity.X) < Type.MaxBackwardSpeed)
                {
                    float force = currentGear.GearBrakeForce; //: Type.DriveBackwardForce;
                    force *= rightTrackThrottle;
                    force *= slopeBackwardForceCoeffient;
                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, -tracksPositionYOffset, 0));
                }
            }

            //LinearVelocity
            if (onGround && localLinearVelocity != Vec3.Zero)
            {
                Vec3 velocity = localLinearVelocity;
                velocity.Y = 0;
                chassisBody.LinearVelocity = chassisBody.Rotation * velocity;
            }

            bool stop = false; // onGround && leftTrackThrottle == 0 && rightTrackThrottle == 0;

            bool noLinearVelocity  = chassisBody.LinearVelocity.Equals(Vec3.Zero, .2f);
            bool noAngularVelocity = chassisBody.AngularVelocity.Equals(Vec3.Zero, .2f);

            //AngularDamping
            if (onGround)
            {
                //LinearDamping
                float linearDamping;
                if (stop)
                {
                    linearDamping = noLinearVelocity ? 1 : 1;
                }
                else
                {
                    linearDamping = .15f;
                }
                chassisBody.LinearDamping = linearDamping + slopeLinearDampingAddition;

                if (stop && noAngularVelocity)
                {
                    chassisBody.AngularDamping = 5;
                }
                else
                {
                    chassisBody.AngularDamping = 1;
                }
            }
            else
            {
                chassisBody.AngularDamping = 0.55f;
                chassisBody.LinearDamping  = 0.05f;
            }
        }
Ejemplo n.º 5
0
        private void TickIntellect()
        {
            GUIshit();
            MapObjectAttachedParticle JetFire1 = GetFirstAttachedObjectByAlias("JetFire1") as MapObjectAttachedParticle;
            MapObjectAttachedParticle JetFire2 = GetFirstAttachedObjectByAlias("JetFire2") as MapObjectAttachedParticle;
            float speed = GetRealSpeed();

            AKunit akunit = GetPlayerUnit() as AKunit;

            Vec3   dir        = AKVTOLBody.Rotation.GetForward();
            Radian slopeAngle = MathFunctions.ATan(dir.Z, dir.ToVec2().Length());

            MASS = 0;
            foreach (Body body in PhysicsModel.Bodies)
            {
                MASS += body.Mass;
            }

            ShiftBooster();

            AKVTOLOn = Intellect != null && Intellect.IsActive();
            // GUItest();
            ALTray();

            //engine force + sound pitch control
            if (Intellect.IsControlKeyPressed(GameControlKeys.Jump))
            {
                if (akunit != null)
                {
                    akunit.GunsTryFire(false);
                }
            }

            if (Intellect.IsControlKeyPressed(GameControlKeys.Forward))
            {
                force += forceadd;
            }
            else if (Intellect.IsControlKeyPressed(GameControlKeys.Backward))
            {
                force -= forceadd;
            }
            else
            {
            }

            if (Intellect.IsControlKeyPressed(GameControlKeys.VerticleTakeOff_L_EngineUp))
            {
                EngineDir += 2f;
            }
            else if (Intellect.IsControlKeyPressed(GameControlKeys.VerticleTakeOff_L_EngineDown))
            {
                EngineDir -= 2f;
            }
            else
            {
            }

            MathFunctions.Clamp(ref EngineDir, 0, 90);

            EngineApp.Instance.ScreenGuiRenderer.AddText("Throttle: " + force, new Vec2(.6f, .1f));

            if (JetFire1 != null && JetFire2 != null)
            {
                if (force > 85f)
                {
                    JetFire1.Visible = true;
                    JetFire2.Visible = true;
                }
                else
                {
                    JetFire1.Visible = false;
                    JetFire2.Visible = false;
                }
            }

            enpitch = 0.8f + (0.6f * (force / 100));
            MathFunctions.Clamp(ref force, 0.1f, 100);
            MathFunctions.Clamp(ref enpitch, 0.8f, 1.4f);

            //update jet channel position and pitch
            if (rotorSoundChannel != null)
            {
                //update channel
                rotorSoundChannel.Pitch    = enpitch;
                rotorSoundChannel.Volume   = 1;
                rotorSoundChannel.Position = Position;
                //rotorSoundChannel.MinDistance = 10;
            }

            //end of engine force + sound pitch control

            //Forces
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //start VTOL Pitch (Y turn)
            if (Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Up) || Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Down))
            {
                float AUp   = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Up) / 2;
                float ADown = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Down) / 2;
                Hpitch += (AUp - ADown);
                MathFunctions.Clamp(ref Hpitch, -10, 10);
            }
            else
            {
                if (Hpitch != 0)
                {
                    Hpitch -= Hpitch / 5;

                    if ((Hpitch - (Hpitch % 1)) == 0)
                    {
                        Hpitch = 0;
                    }
                }
                else
                {
                    float mammadpitch = (AKVTOLBody.AngularVelocity * AKVTOLBody.Rotation.GetInverse()).Y * 2;

                    MathFunctions.Clamp(ref mammadpitch, -10f, 10);
                    AKVTOLBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta,
                                        AKVTOLBody.Rotation * new Vec3(0, 0, -mammadpitch) * MASS, new Vec3(-8, 0, 0));

                    EngineApp.Instance.ScreenGuiRenderer.AddText("MammadPitch: " + mammadpitch.ToString(), new Vec2(.1f, .2f));
                }
            }

            if (Hpitch != 0)
            {
                AKVTOLBody.AddForce(ForceType.GlobalTorque, TickDelta,
                                    AKVTOLBody.Rotation * new Vec3(0, Hpitch, 0) * MASS, Vec3.Zero);
            }
            //end of VTOL pitch (Y turn)

            //start jet Z turn
            if (Intellect.IsControlKeyPressed(GameControlKeys.Right) || Intellect.IsControlKeyPressed(GameControlKeys.Left))
            {
                float right = Intellect.GetControlKeyStrength(GameControlKeys.Right) / 2;
                float left  = Intellect.GetControlKeyStrength(GameControlKeys.Left) / 2;
                TrunZ += (left - right);
                MathFunctions.Clamp(ref TrunZ, -10, 10);

                AKVTOLBody.AddForce(ForceType.LocalTorque, TickDelta,
                                    new Vec3(0, 0, TrunZ * 2) * MASS, Vec3.Zero);
            }
            else
            {
                TrunZ = 0;
            }
            //end of jet Z turn

            //start jet X turn
            if (Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Right) || Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Left))
            {
                float rightX = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Right) / 2;
                float leftX  = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Left) / 2;
                TrunX += (rightX - leftX);
                MathFunctions.Clamp(ref TrunX, -10, 10);

                AKVTOLBody.AddForce(ForceType.GlobalTorque, TickDelta,
                                    AKVTOLBody.Rotation * new Vec3(TrunX * 2, 0, 0) * MASS, Vec3.Zero);
            }
            else
            {
                TrunX = 0;
            }

            float SHOOT = AKVTOLBody.Rotation.GetInverse().ToAngles().Roll; //1 - Rotation.GetUp().Z;

            if (SHOOT < 0)
            {
                SHOOT = -SHOOT;
            }
            if (SHOOT > 90)
            {
                SHOOT = 90 - (SHOOT - 90);
            }

            AKVTOLBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta,
                                AKVTOLBody.Rotation * new Vec3(0, 0, -SHOOT / 180) * MASS, new Vec3(-8, 0, 0));

            //end of jet X turn

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //adding anty  Y movment force
            float Yshit = (AKVTOLBody.LinearVelocity * Rotation.GetInverse()).Y;

            EngineApp.Instance.ScreenGuiRenderer.AddText("Yshit: " + Yshit.ToString(), new Vec2(.6f, .3f));
            EngineApp.Instance.ScreenGuiRenderer.AddText("roll: " + Rotation.ToAngles().Roll, new Vec2(.6f, .35f));
            EngineApp.Instance.ScreenGuiRenderer.AddText("roll: " + (Rotation.GetInverse().ToAngles()).ToString(), new Vec2(.6f, .4f));
            EngineApp.Instance.ScreenGuiRenderer.AddText("Edir: " + EngineDir.ToString(), new Vec2(.1f, .6f));

            //start of adding force

            MathFunctions.Clamp(ref force, 0.1f, 100);

            EngineApp.Instance.ScreenGuiRenderer.AddText("speed: " + GetRealSpeed().ToString(), new Vec2(.6f, .15f));
            GUItest();
            //anti gravity when jet have speed (wings force)

            float antyshityforcy = GetRealSpeed() / 10;

            float slopeangleshit = 1.5f;

            MathFunctions.Clamp(ref antyshityforcy, 0, 10);
            if (slopeAngle > 0)
            {
                slopeangleshit = 1.5f - slopeAngle;
            }
            else
            {
                slopeangleshit = 0.5f;
            }

            if (GetRealSpeed() > 0)
            {
                AKVTOLBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                    new Vec3(0, 0, antyshityforcy * slopeangleshit) * MASS, Vec3.Zero);
            }

            //if Max Alt is not reached add jet motor force
            if (AKVTOLBody.Position.Z < Type.MaxAlt)
            {
                AKVTOLBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta,
                                    AKVTOLBody.Rotation * new Vec3(force / 2f * ((90 - EngineDir) / 90), 0, force / 8f * (EngineDir / 90)) * MASS, Vec3.Zero);
            }

            //dampings
            AKVTOLBody.AngularDamping = 2f + (speed / 60);
            AKVTOLBody.LinearDamping  = 0.6f;

            ServoMotor Lenginem = PhysicsModel.GetMotor("LEngineM") as ServoMotor;
            ServoMotor Renginem = PhysicsModel.GetMotor("REngineM") as ServoMotor;

            if (Lenginem != null && Renginem != null)
            {
                float EngingDirRad = EngineDir * MathFunctions.PI / 180;
                Renginem.DesiredAngle = EngingDirRad;
                Lenginem.DesiredAngle = EngingDirRad;
            }
        }
Ejemplo n.º 6
0
        void TickRearWheels()
        {
            float leftwheelForce  = 0;
            float rightwheelForce = 0;

            if (Intellect != null)
            {
                ServoMotor rightwheel = PhysicsModel.GetMotor("rightwheelMotor") as ServoMotor;
                ServoMotor leftwheel  = PhysicsModel.GetMotor("leftwheelMotor") as ServoMotor;


                if (rightwheel != null)
                {
                    if (leftwheel != null)
                    {
                        float speed = Type.Rotationspeed;
                        MathFunctions.Clamp(ref speed, Type.Rotationspeed, Type.Rotationspeed);
                        Radian needAngle = leftwheel.DesiredAngle;
                        if (Intellect.IsControlKeyPressed(GameControlKeys.Left))
                        {
                            if (3 > 2)
                            {
                                leftwheelForce  += speed;
                                rightwheelForce -= speed;
                            }
                            needAngle += Type.Rotation;
                        }

                        else if (Intellect.IsControlKeyPressed(GameControlKeys.Right))
                        {
                            if (3 > 2)
                            {
                                leftwheelForce  -= speed;
                                rightwheelForce += speed;
                            }

                            needAngle -= Type.Rotation;
                        }

                        else
                        {
                            needAngle = 0f;
                        }

                        MathFunctions.Clamp(ref needAngle, new Degree(-Type.Rotationradius).InRadians(),
                                            new Degree(Type.Rotationradius).InRadians());
                        rightwheel.DesiredAngle = needAngle;
                        leftwheel.DesiredAngle  = needAngle;
                    }
                }
            }
            ServoMotor motor = PhysicsModel.GetMotor("upMotor") as ServoMotor;

            if (motor != null)
            {
                Radian needAngle = motor.DesiredAngle;

                needAngle += Intellect.GetControlKeyStrength(GameControlKeys.Fire1) * Type.Forkupspeed;
                needAngle -= Intellect.GetControlKeyStrength(GameControlKeys.Fire2) * Type.Forkupspeed;

                MathFunctions.Clamp(ref needAngle,
                                    new Degree(-0.0f).InRadians(), new Degree(Type.Forkupmax).InRadians());

                motor.DesiredAngle = needAngle;
            }
        }
Ejemplo n.º 7
0
        private void TickIntellect()
        {
            ShiftBooster();

            HelliOn = Intellect != null && Intellect.IsActive();
            // GUItest();

            //finding motors
            GearedMotor main = PhysicsModel.GetMotor("hellimain") as GearedMotor;
            GearedMotor back = PhysicsModel.GetMotor("helliback") as GearedMotor;

            if (HelliOn)
            {
                main.Enabled = true;
                back.Enabled = true;
            }

            //engine force + sound pitch control

            if (Intellect.IsControlKeyPressed(GameControlKeys.Forward))
            {
                force   += forceadd;
                enpitch += 0.02f;
            }
            else if (Intellect.IsControlKeyPressed(GameControlKeys.Backward))
            {
                dec      = true;
                force   -= forceadd;
                enpitch -= 0.02f;
            }
            else
            {
                dec      = false;
                enpitch -= 0.01f;
                if (force > 50)
                {
                    force -= forceadd;
                }
                if (force < 50)
                {
                    force += forceadd;
                }
            }

            MathFunctions.Clamp(ref force, 0.1f, 100 + Type.MaxForce);
            MathFunctions.Clamp(ref enpitch, 0.8f, 1.3f);

            //update helli channel position and pitch
            if (rotorSoundChannel != null)
            {
                //update channel
                rotorSoundChannel.Pitch    = enpitch;
                rotorSoundChannel.Volume   = 1;
                rotorSoundChannel.Position = Position;
                //rotorSoundChannel.MinDistance = 10;
            }

            //end of engine force + sound pitch control

            //Forces
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //start helli Pitch
            if (Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Up) || Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Down))
            {
                float AUp   = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Up) / 2;
                float ADown = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Down) / 2;
                Hpitch += (AUp - ADown);
                MathFunctions.Clamp(ref Hpitch, -10, 10);

                HelliBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta,
                                   HelliBody.Rotation * new Vec3(0, 0, Hpitch / 2) * HelliBody.Mass, new Vec3(-2, 0, 0));
            }
            else
            {
                Hpitch = 0;
            }
            //end of helli pitch

            //start helli Z turn
            if (Intellect.IsControlKeyPressed(GameControlKeys.Right) || Intellect.IsControlKeyPressed(GameControlKeys.Left))
            {
                float right = Intellect.GetControlKeyStrength(GameControlKeys.Right) / 2;
                float left  = Intellect.GetControlKeyStrength(GameControlKeys.Left) / 2;
                TrunZ += (left - right);
                MathFunctions.Clamp(ref TrunZ, -10, 10);

                HelliBody.AddForce(ForceType.GlobalTorque, TickDelta,
                                   HelliBody.Rotation * new Vec3(0, 0, TrunZ) * HelliBody.Mass, Vec3.Zero);
            }
            else
            {
                TrunZ = 0;
            }

            //end of helli Z turn

            //start helli X turn
            if (Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Right) || Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Left))
            {
                float rightX = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Right) / 2;
                float leftX  = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Left) / 2;
                TrunX += (rightX - leftX);
                MathFunctions.Clamp(ref TrunX, -10, 10);

                HelliBody.AddForce(ForceType.GlobalTorque, TickDelta,
                                   HelliBody.Rotation * new Vec3(TrunX / 5, 0, 0) * HelliBody.Mass, Vec3.Zero);
            }
            else
            {
                TrunX = 0;
            }
            //end of helli X turn

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //start of adding force

            MathFunctions.Clamp(ref force, 0.1f, 100);

            //anti gravity when helli is not decending
            if (dec == false)
            {
                HelliBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta,
                                   new Vec3(0, 0, 2) * HelliBody.Mass, Vec3.Zero);
            }

            //if Max Alt is not reached add helli motor force
            if (GetRealAlt() < Type.MaxAlt)
            {
                HelliBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta,
                                   HelliBody.Rotation * 2 * new Vec3(0, 0, force / 7) * HelliBody.Mass, Vec3.Zero);
            }

            //dampings
            HelliBody.AngularDamping = 1.5f;
            HelliBody.LinearDamping  = 0.4f;

            //another anti gravity force
            if (HelliBody.LinearVelocity.Z < 0)
            {
                HelliBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta,
                                   HelliBody.Rotation * new Vec3(0, 0, -HelliBody.LinearVelocity.Z) * HelliBody.Mass, Vec3.Zero);
            }
        }
Ejemplo n.º 8
0
        private void TickRotation()
        {
            bool onGround = LFWheel.onGround || RFWheel.onGround;

            float carspeed        = GetWheelsSpeed();
            float LFWheelThrottle = 0;
            float RFWheelThrottle = 0;

            if (Intellect != null)
            {
                Body WFR = PhysicsModel.GetBody("FR");
                Body WFL = PhysicsModel.GetBody("FL");
                Body WRR = PhysicsModel.GetBody("RR");
                Body WRL = PhysicsModel.GetBody("RL");

                float wheelspeed = GetWheelsSpeed() * 2;
                Vec3  Wspeed     = new Vec3(0, wheelspeed,
                                            0) * chassisBody.Rotation.GetNormalize();

                if (onGround)
                {
                    WFR.AngularVelocity = Wspeed;
                    WFL.AngularVelocity = Wspeed;
                    WRR.AngularVelocity = Wspeed;
                    WRL.AngularVelocity = Wspeed;
                }
                {
                    ServoMotor motor_1 = PhysicsModel.GetMotor("wheel1") as ServoMotor;
                    ServoMotor motor_2 = PhysicsModel.GetMotor("wheel2") as ServoMotor;

                    if (motor_1 != null)
                    {
                        if (motor_2 != null)
                        {
                            float turnspeed = 0.5f;
                            MathFunctions.Clamp(ref turnspeed, 0.5f, 0.5f);
                            Radian needAngle = motor_1.DesiredAngle;
                            if (Intellect.IsControlKeyPressed(GameControlKeys.Left))
                            {
                                if (carspeed > 2)
                                {
                                    LFWheelThrottle -= turnspeed;
                                    RFWheelThrottle += turnspeed;
                                }
                                if (carspeed < -1)
                                {
                                    LFWheelThrottle += turnspeed;
                                    RFWheelThrottle -= turnspeed;
                                }
                                needAngle -= 0.2f;
                            }
                            else if (Intellect.IsControlKeyPressed(GameControlKeys.Right))
                            {
                                if (carspeed > 2)
                                {
                                    LFWheelThrottle += turnspeed;
                                    RFWheelThrottle -= turnspeed;
                                }
                                if (carspeed < -1)
                                {
                                    LFWheelThrottle -= turnspeed;
                                    RFWheelThrottle += turnspeed;
                                }
                                needAngle += 0.2f;
                            }
                            else
                            {
                                needAngle = 0f;
                            }

                            MathFunctions.Clamp(ref needAngle, new Degree(-37.0f).InRadians(),
                                                new Degree(37.0f).InRadians());
                            motor_1.DesiredAngle = needAngle;
                            motor_2.DesiredAngle = needAngle;
                        }
                    }
                }
            }
        }