GetControlKeyStrength() public méthode

public GetControlKeyStrength ( GameControlKeys key ) : float
key GameControlKeys
Résultat float
Exemple #1
0
        void TickFrontWheels()
        {
            Vec3  Velocity  = forkliftBody.LinearVelocity * forkliftBody.Rotation.GetInverse();
            bool  onGround  = leftWheel.onGround || rightWheel.onGround;
            float leftwheel = 0;

            if (Intellect != null)
            {
                float forward = Intellect.GetControlKeyStrength(GameControlKeys.Forward);
                leftwheel += forward;

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

                MathFunctions.Clamp(ref leftwheel, -1, 1);
            }
            //return if no throttle and sleeping
            if (forkliftBody.Sleeping && leftwheelBody.Sleeping && rightwheelBody.Sleeping &&
                wheelRearRightBody.Sleeping && wheelRearLeftBody.Sleeping && leftwheel == 0)
            {
                return;
            }

            if (leftWheel.onGround && rightWheel.onGround)
            {
                if (leftwheel > 0 && Velocity.X < Type.FMaximumspeedgear1)
                {
                    float force = Velocity.X > 0 ? Type.Forwardgear1force : Type.Brakeforcegear1;
                    force *= leftwheel;
                    forkliftBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                          new Vec3(force, 0, 0), new Vec3(0, 0, 0));
                }



                if (leftwheel < 0 && (-Velocity.X) < Type.BMaximumspeedgear1)
                {
                    float force = -Velocity.X < 0 ? Type.Brakeforcegear1 : Type.Backwardgear1force;
                    force *= leftwheel;
                    forkliftBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                          new Vec3(force, 0, 0), new Vec3(0, 0, 0));
                }
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        private void TickChassis_hand_brake()
        {
            skidsound(false);
            bool onGround = LRWheel.onGround || RRWheel.onGround;

            float hand_brake_f = 0;
            float hand_brake_b = 0;

            if (Intellect != null)
            {
                Ñar_particle();
                float h_brake = Intellect.GetControlKeyStrength(GameControlKeys.Jump);
                hand_brake_f += h_brake;
                hand_brake_b -= h_brake;
                MathFunctions.Clamp(ref hand_brake_f, -1, 1);
                MathFunctions.Clamp(ref hand_brake_b, -1, 1);
            }

            Vec3  localLinearVelocity = chassisBody.LinearVelocity * chassisBody.Rotation.GetInverse();
            float tm_hb = Type.Hand_brake / 2;

            if (LRWheel.onGround && RRWheel.onGround)
            {
                if (hand_brake_f > 0 && localLinearVelocity.X < Type.Max_forward_speed)
                {
                    float force = localLinearVelocity.X > 0 ? tm_hb : Type.Hand_brake;
                    force *= hand_brake_f;

                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, 0, 0));
                }

                if (hand_brake_b < 0 && (-localLinearVelocity.X) < Type.Max_backward_speed)
                {
                    float force = localLinearVelocity.X > 0 ? Type.Hand_brake : tm_hb;
                    force *= hand_brake_b;

                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, 0, 0));
                }
            }
        }
        void TickIntellect( Intellect intellect )
        {
            Vec2 forceVec = Vec2.Zero;

            if( forceMoveVectorTimer != 0 )
            {
                forceVec = forceMoveVector;
            }
            else
            {
                Vec2 vec = Vec2.Zero;

                vec.X += intellect.GetControlKeyStrength( GameControlKeys.Forward );
                vec.X -= intellect.GetControlKeyStrength( GameControlKeys.Backward );
                vec.Y += intellect.GetControlKeyStrength( GameControlKeys.Left );
                vec.Y -= intellect.GetControlKeyStrength( GameControlKeys.Right );

                forceVec = ( new Vec3( vec.X, vec.Y, 0 ) * Rotation ).ToVec2();

                //TPS arcade specific (camera observe)
                //set forceVec depending on camera orientation
                if( GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade && forceVec != Vec2.Zero )
                {
                    if( Intellect != null && PlayerIntellect.Instance == Intellect )
                    {
                        //!!!!!!not adapted for networking
                        //using RendererWorld.Instance.DefaultCamera is bad

                        Vec2 diff = Position.ToVec2() - RendererWorld.Instance.DefaultCamera.
                            Position.ToVec2();
                        Degree angle = new Radian( MathFunctions.ATan( diff.Y, diff.X ) );
                        Degree vecAngle = new Radian( MathFunctions.ATan( -vec.Y, vec.X ) );
                        Quat rot = new Angles( 0, 0, vecAngle - angle ).ToQuat();
                        forceVec = ( rot * new Vec3( 1, 0, 0 ) ).ToVec2();
                    }
                }

                if( forceVec != Vec2.Zero )
                {
                    float length = forceVec.Length();
                    if( length > 1 )
                        forceVec /= length;
                }
            }

            if( forceVec != Vec2.Zero )
            {
                float velocityCoefficient = 1;
                if( FastMoveInfluence != null )
                    velocityCoefficient = FastMoveInfluence.Type.Coefficient;

                float maxVelocity;
                float force;

                if( IsOnGround() )
                {
                    maxVelocity = Type.WalkMaxVelocity;
                    force = Type.WalkForce;
                }
                else
                {
                    maxVelocity = Type.FlyControlMaxVelocity;
                    force = Type.FlyControlForce;
                }

                maxVelocity *= forceVec.LengthFast();

                //velocityCoefficient
                maxVelocity *= velocityCoefficient;
                force *= velocityCoefficient;

                if( mainBody.LinearVelocity.LengthFast() < maxVelocity )
                    mainBody.AddForce( ForceType.Global, 0, new Vec3( forceVec.X, forceVec.Y, 0 ) *
                        force * TickDelta, Vec3.Zero );
            }

            lastTickForceVector = forceVec;
        }
Exemple #5
0
        void TickIntellect( Intellect intellect )
        {
            Vec2 forceVec = Vec2.Zero;

            if( forceMoveVectorTimer != 0 )
            {
                forceVec = forceMoveVector;
            }
            else
            {
                Vec2 vec = Vec2.Zero;

                vec.X += intellect.GetControlKeyStrength( GameControlKeys.Forward );
                vec.X -= intellect.GetControlKeyStrength( GameControlKeys.Backward );
                vec.Y += intellect.GetControlKeyStrength( GameControlKeys.Left );
                vec.Y -= intellect.GetControlKeyStrength( GameControlKeys.Right );

                forceVec = ( new Vec3( vec.X, vec.Y, 0 ) * Rotation ).ToVec2();

                //TPS arcade specific (camera observe)
                //set forceVec depending on camera orientation
                if( GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade && forceVec != Vec2.Zero )
                {
                    if( Intellect != null && PlayerIntellect.Instance == Intellect )
                    {
                        //this is not adapted for networking.
                        //using RendererWorld.Instance.DefaultCamera is bad.

                        Vec2 diff = Position.ToVec2() - RendererWorld.Instance.DefaultCamera.
                            Position.ToVec2();
                        Degree angle = new Radian( MathFunctions.ATan( diff.Y, diff.X ) );
                        Degree vecAngle = new Radian( MathFunctions.ATan( -vec.Y, vec.X ) );
                        Quat rot = new Angles( 0, 0, vecAngle - angle ).ToQuat();
                        forceVec = ( rot * new Vec3( 1, 0, 0 ) ).ToVec2();
                    }
                }

                if( forceVec != Vec2.Zero )
                {
                    float length = forceVec.Length();
                    if( length > 1 )
                        forceVec /= length;
                }
            }

            if( forceVec != Vec2.Zero )
            {
                float speedCoefficient = 1;
                if( FastMoveInfluence != null )
                    speedCoefficient = FastMoveInfluence.Type.Coefficient;

                float maxSpeed;
                float force;

                if( IsOnGround() )
                {
                    //calcualate maxSpeed and force on ground.

                    Vec2 localVec = ( new Vec3( forceVec.X, forceVec.Y, 0 ) * Rotation.GetInverse() ).ToVec2();

                    float absSum = Math.Abs( localVec.X ) + Math.Abs( localVec.Y );
                    if( absSum > 1 )
                        localVec /= absSum;

                    bool running = IsNeedRun();

                    maxSpeed = 0;
                    force = 0;

                    if( Math.Abs( localVec.X ) >= .001f )
                    {
                        //forward and backward
                        float speedX;
                        if( localVec.X > 0 )
                            speedX = running ? Type.RunForwardMaxSpeed : Type.WalkForwardMaxSpeed;
                        else
                            speedX = running ? Type.RunBackwardMaxSpeed : Type.WalkBackwardMaxSpeed;
                        maxSpeed += speedX * Math.Abs( localVec.X );
                        force += ( running ? Type.RunForce : Type.WalkForce ) * Math.Abs( localVec.X );
                    }

                    if( Math.Abs( localVec.Y ) >= .001f )
                    {
                        //left and right
                        maxSpeed += ( running ? Type.RunSideMaxSpeed : Type.WalkSideMaxSpeed ) *
                            Math.Abs( localVec.Y );
                        force += ( running ? Type.RunForce : Type.WalkForce ) * Math.Abs( localVec.Y );
                    }
                }
                else
                {
                    //calcualate maxSpeed and force when flying.
                    maxSpeed = Type.FlyControlMaxSpeed;
                    force = Type.FlyControlForce;
                }

                //speedCoefficient
                maxSpeed *= speedCoefficient;
                force *= speedCoefficient;

                if( mainBody.LinearVelocity.LengthFast() < maxSpeed )
                {
                    mainBody.AddForce( ForceType.Global, 0, new Vec3( forceVec.X, forceVec.Y, 0 ) *
                        force * TickDelta, Vec3.Zero );
                }
            }

            lastTickForceVector = forceVec;
        }
Exemple #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;
            }
        }
Exemple #7
0
        private void TickChassis_forward_wheel()
        {
            bool onGround = LFWheel.onGround || RFWheel.onGround;

            float LFWheelThrottle = 0;
            float RFWheelThrottle = 0;

            if (Intellect != null)
            {
                float left = Intellect.GetControlKeyStrength(GameControlKeys.Left);
                LFWheelThrottle -= left * 2;
                RFWheelThrottle += left * 2;

                float right = Intellect.GetControlKeyStrength(GameControlKeys.Right);
                LFWheelThrottle += right * 2;
                RFWheelThrottle -= right * 2;

                MathFunctions.Clamp(ref LFWheelThrottle, -1, 1);
                MathFunctions.Clamp(ref RFWheelThrottle, -1, 1);
            }

            //return if no throttle and sleeping
            if (chassisBody.Sleeping && LFWheelThrottle == 0 && RFWheelThrottle == 0)
            {
                return;
            }

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

            float sp = GetWheelsSpeed();
            //add drive force
            float slopeLeftForceCoeffient;
            float slopeRightForceCoeffient;
            float radius = 0;

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

                //%_forward_speed==============================================
                float sf1   = (Type.Max_forward_speed * 1) / 100;
                float sf10  = (Type.Max_forward_speed * 10) / 100;
                float sf20  = (Type.Max_forward_speed * 20) / 100;
                float sf30  = (Type.Max_forward_speed * 30) / 100;
                float sf40  = (Type.Max_forward_speed * 40) / 100;
                float sf50  = (Type.Max_forward_speed * 50) / 100;
                float sf60  = (Type.Max_forward_speed * 60) / 100;
                float sf70  = (Type.Max_forward_speed * 70) / 100;
                float sf80  = (Type.Max_forward_speed * 80) / 100;
                float sf90  = (Type.Max_forward_speed * 90) / 100;
                float sf110 = (Type.Max_forward_speed * 110) / 100;
                //%_forward_speed==============================================

                if (sp < 1)
                {
                    radius = Type.Speed10_rotation;
                }
                if (sp >= sf1 & sp < sf10)
                {
                    radius = Type.Speed10_rotation;
                }
                if (sp >= sf10 & sp < sf20)
                {
                    radius = Type.Speed20_rotation;
                }
                if (sp >= sf20 & sp < sf30)
                {
                    radius = Type.Speed30_rotation;
                }
                if (sp >= sf30 & sp < sf40)
                {
                    radius = Type.Speed40_rotation;
                }
                if (sp >= sf40 & sp < sf50)
                {
                    radius = Type.Speed50_rotation;
                }
                if (sp >= sf50 & sp < sf60)
                {
                    radius = Type.Speed60_rotation;
                }
                if (sp >= sf60 & sp < sf70)
                {
                    radius = Type.Speed70_rotation;
                }
                if (sp >= sf70 & sp < sf80)
                {
                    radius = Type.Speed80_rotation;
                }
                if (sp >= sf80 & sp < sf90)
                {
                    radius = Type.Speed90_rotation;
                }
                if (sp >= sf90 & sp < sf110)
                {
                    radius = Type.Speed100_rotation;
                }

                //==================================
                slopeLeftForceCoeffient = radius;
                //zero
                if (slopeAngle > maxAngle)
                {
                    slopeLeftForceCoeffient = 0;
                }
                slopeRightForceCoeffient = radius;
                //zero
                if (slopeAngle < -maxAngle)
                {
                    slopeRightForceCoeffient = 0;
                }
                //==================================

                MathFunctions.Clamp(ref slopeLeftForceCoeffient, -Type.Max_force_angle, Type.Max_force_angle);
                MathFunctions.Clamp(ref slopeRightForceCoeffient, -Type.Max_force_angle, Type.Max_force_angle);
            }

            if (LFWheel.onGround)
            {
                if (LFWheelThrottle > 0)
                {
                    float force = sp;
                    force *= LFWheelThrottle;
                    force *= slopeLeftForceCoeffient;
                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, LFWheelPositionYOffset, 0));
                }

                if (LFWheelThrottle < 0)
                {
                    float force = sp;
                    force *= LFWheelThrottle;
                    force *= slopeLeftForceCoeffient;
                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, LFWheelPositionYOffset, 0));
                }
            }

            if (RFWheel.onGround)
            {
                if (RFWheelThrottle > 0)
                {
                    float force = sp;
                    force *= RFWheelThrottle;
                    force *= slopeRightForceCoeffient;
                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, -RFWheelPositionYOffset, 0));
                }

                if (RFWheelThrottle < 0)
                {
                    float force = sp;
                    force *= RFWheelThrottle;
                    force *= slopeRightForceCoeffient;
                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, -RFWheelPositionYOffset, 0));
                }
            }
        }
Exemple #8
0
        private void TickChassis_backward_wheel()
        {
            bool onGround = LRWheel.onGround || RRWheel.onGround;

            float LRWheelThrottle = 0;
            float RRWheelThrottle = 0;

            if (Intellect != null)
            {
                float forward = Intellect.GetControlKeyStrength(GameControlKeys.Forward);
                LRWheelThrottle += forward;
                RRWheelThrottle += forward;

                float backward = Intellect.GetControlKeyStrength(GameControlKeys.Backward);
                LRWheelThrottle -= backward;
                RRWheelThrottle -= backward;

                MathFunctions.Clamp(ref LRWheelThrottle, -1, 1);
                MathFunctions.Clamp(ref RRWheelThrottle, -1, 1);
            }

            //return if no throttle and sleeping
            if (chassisBody.Sleeping && LRWheelThrottle == 0 && RRWheelThrottle == 0)
            {
                return;
            }

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

            if (LRWheel.onGround)
            {
                if (LRWheelThrottle > 0 && localLinearVelocity.X < Type.Max_forward_speed)
                {
                    float force = localLinearVelocity.X > 0 ? Type.Drive_forward_force : Type.Brake_force;
                    force *= LRWheelThrottle;

                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, 0, 0));
                }

                if (LRWheelThrottle < 0 && (-localLinearVelocity.X) < Type.Max_backward_speed)
                {
                    float force = localLinearVelocity.X > 0 ? Type.Brake_force : Type.Drive_backward_force;
                    force *= LRWheelThrottle;

                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, 0, 0));
                }
            }

            if (RRWheel.onGround)
            {
                if (RRWheelThrottle > 0 && localLinearVelocity.X < Type.Max_forward_speed)
                {
                    float force = localLinearVelocity.X > 0 ? Type.Drive_forward_force : Type.Brake_force;
                    force *= RRWheelThrottle;

                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, 0, 0));
                }

                if (RRWheelThrottle < 0 && (-localLinearVelocity.X) < Type.Max_backward_speed)
                {
                    float force = localLinearVelocity.X > 0 ? Type.Brake_force : Type.Drive_backward_force;
                    force *= RRWheelThrottle;

                    chassisBody.AddForce(ForceType.LocalAtLocalPos, TickDelta,
                                         new Vec3(force, 0, 0), new Vec3(0, 0, 0));
                }
            }

            #endregion Backward wheel

            #region Wheel friction

            float hand_brake_wheelfriction = 0;
            if (Intellect != null)
            {
                float hbwf = Intellect.GetControlKeyStrength(GameControlKeys.Jump);
                hand_brake_wheelfriction += hbwf;
                MathFunctions.Clamp(ref hand_brake_wheelfriction, 0, 1);
            }

            if (hand_brake_wheelfriction == 0 && onGround && localLinearVelocity != Vec3.Zero)
            {
                Vec3  velocity       = localLinearVelocity;
                float wheel_friction = Type.Wheel_friction;
                if (velocity.Y > 0.2f)
                {
                    velocity.Y -= wheel_friction;
                    if (velocity.Y == 0)
                    {
                        wheel_friction = 0;
                    }
                }
                if (-velocity.Y > 0.2f)
                {
                    velocity.Y += wheel_friction;
                    if (velocity.Y == 0)
                    {
                        wheel_friction = 0;
                    }
                }

                chassisBody.LinearVelocity = chassisBody.Rotation * velocity;
            }
            if (hand_brake_wheelfriction > 0 && onGround && localLinearVelocity != Vec3.Zero)
            {
                Vec3  velocity       = localLinearVelocity;
                float wheel_friction = Type.Hand_brake_wheelfriction;
                if (velocity.Y > 0.2f)
                {
                    velocity.Y -= wheel_friction;
                    if (velocity.Y == 0)
                    {
                        wheel_friction = 0;
                    }
                }
                if (-velocity.Y > 0.2f)
                {
                    velocity.Y += wheel_friction;
                    if (velocity.Y == 0)
                    {
                        wheel_friction = 0;
                    }
                }

                chassisBody.LinearVelocity = chassisBody.Rotation * velocity;
            }

            #endregion Wheel friction

            #region Force free stop car

            bool stop = onGround && LRWheelThrottle == 0 && RRWheelThrottle == 0;

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

            //LinearDamping
            float linearDamping;
            if (stop)
            {
                linearDamping = noLinearVelocity ? 5 : Type.Force_freestop_car;
            }
            else
            {
                linearDamping = Type.Force_freestop_car;
            }
            chassisBody.LinearDamping = linearDamping;

            //AngularDamping
            if (onGround)
            {
                if (stop && noAngularVelocity)
                {
                    chassisBody.AngularDamping = 5;
                }
                else
                {
                    chassisBody.AngularDamping = 1;
                }
            }
            else
            {
                chassisBody.AngularDamping = .15f;
            }

            //sleeping
            if (!chassisBody.Sleeping && stop && noLinearVelocity && noAngularVelocity)
            {
                chassisSleepTimer += TickDelta;
                if (chassisSleepTimer > 1)
                {
                    chassisBody.Sleeping = true;
                }
            }
            else
            {
                chassisSleepTimer = 0;
            }
        }
Exemple #9
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.ArrowUp) || Intellect.IsControlKeyPressed(GameControlKeys.ArrowDown))
            {
                float AUp   = Intellect.GetControlKeyStrength(GameControlKeys.ArrowUp) / 2;
                float ADown = Intellect.GetControlKeyStrength(GameControlKeys.ArrowDown) / 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.ArowRight) || Intellect.IsControlKeyPressed(GameControlKeys.ArowLeft))
            {
                float rightX = Intellect.GetControlKeyStrength(GameControlKeys.ArowRight) / 2;
                float leftX  = Intellect.GetControlKeyStrength(GameControlKeys.ArowLeft) / 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);
            }
        }
Exemple #10
0
        void TickIntellect(Intellect intellect)
        {
            Vec2 forceVec = Vec2.Zero;

            if (forceMoveVectorTimer != 0)
            {
                forceVec = forceMoveVector;
            }
            else
            {
                Vec2 vec = Vec2.Zero;

                vec.X += intellect.GetControlKeyStrength(GameControlKeys.Forward);
                vec.X -= intellect.GetControlKeyStrength(GameControlKeys.Backward);
                vec.Y += intellect.GetControlKeyStrength(GameControlKeys.Left);
                vec.Y -= intellect.GetControlKeyStrength(GameControlKeys.Right);

                forceVec = (new Vec3(vec.X, vec.Y, 0) * Rotation).ToVec2();

                //TPS arcade specific (camera observe)
                //set forceVec depending on camera orientation
                if (GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade && forceVec != Vec2.Zero)
                {
                    if (Intellect != null && PlayerIntellect.Instance == Intellect)
                    {
                        //!!!!!!not adapted for networking
                        //using RendererWorld.Instance.DefaultCamera is bad

                        Vec2 diff = Position.ToVec2() - RendererWorld.Instance.DefaultCamera.
                                    Position.ToVec2();
                        Degree angle    = new Radian(MathFunctions.ATan(diff.Y, diff.X));
                        Degree vecAngle = new Radian(MathFunctions.ATan(-vec.Y, vec.X));
                        Quat   rot      = new Angles(0, 0, vecAngle - angle).ToQuat();
                        forceVec = (rot * new Vec3(1, 0, 0)).ToVec2();
                    }
                }

                if (forceVec != Vec2.Zero)
                {
                    float length = forceVec.Length();
                    if (length > 1)
                    {
                        forceVec /= length;
                    }
                }
            }

            if (forceVec != Vec2.Zero)
            {
                float velocityCoefficient = 1;
                if (FastMoveInfluence != null)
                {
                    velocityCoefficient = FastMoveInfluence.Type.Coefficient;
                }

                float maxVelocity;
                float force;

                if (IsOnGround())
                {
                    maxVelocity = Type.WalkMaxVelocity;
                    force       = Type.WalkForce;
                }
                else
                {
                    maxVelocity = Type.FlyControlMaxVelocity;
                    force       = Type.FlyControlForce;
                }

                maxVelocity *= forceVec.LengthFast();

                //velocityCoefficient
                maxVelocity *= velocityCoefficient;
                force       *= velocityCoefficient;

                if (mainBody.LinearVelocity.LengthFast() < maxVelocity)
                {
                    mainBody.AddForce(ForceType.Global, 0, new Vec3(forceVec.X, forceVec.Y, 0) *
                                      force * TickDelta, Vec3.Zero);
                }
            }

            lastTickForceVector = forceVec;
        }