void UpdateAnimationTree()
        {
            if (EntitySystemWorld.Instance.Simulation && !EntitySystemWorld.Instance.SystemPauseOfSimulation)
            {
                AnimationTree tree = GetFirstAnimationTree();
                if (tree != null)
                {
                    tree.SetParameterValue("weapon", activeWeapon != null ? 1 : 0);

                    Radian horizontalAngle = 0;
                    Radian verticalAngle   = 0;

                    PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
                    if (playerIntellect != null)
                    {
                        Vec2 vec = Vec2.Zero;
                        vec.X += playerIntellect.GetControlKeyStrength(GameControlKeys.Forward);
                        vec.X -= playerIntellect.GetControlKeyStrength(GameControlKeys.Backward);
                        vec.Y += playerIntellect.GetControlKeyStrength(GameControlKeys.Left);
                        vec.Y -= playerIntellect.GetControlKeyStrength(GameControlKeys.Right);
                        if (vec.X < 0)
                        {
                            vec = -vec;
                        }
                        horizontalAngle = MathFunctions.ATan(vec.Y, vec.X);

                        verticalAngle = playerIntellect.LookDirection.Vertical;
                    }

                    tree.SetParameterValue("weaponHorizontalAngle", horizontalAngle.InDegrees());
                    tree.SetParameterValue("weaponVerticalAngle", verticalAngle.InDegrees());
                }
            }
        }
Exemple #2
0
        void MomentaryTurnToPositionUpdate(Vec3 turnToPosition)
        {
            if (turretBody == null || baseBody == null || mainGunAttachedObject == null)
            {
                return;
            }

            Vec3 diff = turnToPosition - Position;

            Radian horizontalAngle = MathFunctions.ATan(diff.Y, diff.X);
            Radian verticalAngle   = MathFunctions.ATan(diff.Z, diff.ToVec2().Length());

            turretBody.Rotation = new Angles(0, 0, -horizontalAngle.InDegrees()).ToQuat();

            Quat rot = baseBody.Rotation.GetInverse() * turretBody.Rotation;

            Quat verticalRot = new Angles(0, verticalAngle.InDegrees(), 0).ToQuat();

            mainGunAttachedObject.PositionOffset = rot * mainGunOffsetPosition;
            mainGunAttachedObject.RotationOffset = rot * verticalRot;
            RecalculateMapBounds();

            if (EntitySystemWorld.Instance.IsServer())
            {
                server_shouldSendTurnToPosition = turnToPosition;
            }
        }
        void DoResetYCoordinateForDynamicBodies()
        {
            foreach (Body body in PhysicsWorld.Instance.MainScene.Bodies)
            {
                if (!body.Sleeping)
                {
                    if (Math.Abs(body.Position.Y) > .005f)
                    {
                        body.Position = new Vec3(body.Position.X, 0, body.Position.Z);
                    }

                    Vec3 forward = body.Rotation.GetForward();
                    if (Math.Abs(forward.Y) > .05f)
                    {
                        forward.Y = 0;
                        forward.Normalize();
                        float angle = MathFunctions.ATan(forward.Z, forward.X);
                        body.Rotation = new Angles(0, MathFunctions.RadToDeg(angle), 0).ToQuat();
                    }

                    if (Math.Abs(body.LinearVelocity.Y) > .01f)
                    {
                        body.LinearVelocity = new Vec3(body.LinearVelocity.X, 0, body.LinearVelocity.Z);
                    }

                    if (Math.Abs(body.AngularVelocity.X) > .05f || Math.Abs(body.AngularVelocity.Z) > .05f)
                    {
                        body.AngularVelocity = new Vec3(0, body.AngularVelocity.Y, 0);
                    }
                }
            }
        }
        void UpdateAnimationTree()
        {
            if (EntitySystemWorld.Instance.Simulation && !EntitySystemWorld.Instance.SystemPauseOfSimulation)
            {
                AnimationTree tree = GetFirstAnimationTree();
                if (tree != null)
                {
                    bool onGround = GetElapsedTimeSinceLastGroundContact() < .2f;                    //IsOnGround();

                    bool   move      = false;
                    Degree moveAngle = 0;
                    float  moveSpeed = 0;
                    if (onGround && GroundRelativeVelocitySmooth.ToVec2().Length() > .05f)
                    {
                        move = true;
                        Vec2   localVec = (Rotation.GetInverse() * GroundRelativeVelocity).ToVec2();
                        Radian angle    = MathFunctions.ATan(localVec.Y, localVec.X);
                        moveAngle = angle.InDegrees();
                        moveSpeed = GroundRelativeVelocity.ToVec2().Length();
                    }

                    tree.SetParameterValue("move", move ? 1 : 0);
                    tree.SetParameterValue("run", move && IsNeedRun() ? 1 : 0);
                    tree.SetParameterValue("moveAngle", moveAngle);
                    tree.SetParameterValue("moveSpeed", moveSpeed);
                    tree.SetParameterValue("fly", !onGround ? 1 : 0);
                }
            }
        }
Exemple #5
0
            //

            public override Radian GetAngle()
            {
                Quat relativeRotation = ((PhysXHingeJoint)Joint).initialRelativeRotationInverse *
                                        (Joint.Body2.Rotation * Joint.Body1.Rotation.GetInverse());

                float cost2 = relativeRotation.W;
                float sint2 = MathFunctions.Sqrt(
                    relativeRotation.X * relativeRotation.X +
                    relativeRotation.Y * relativeRotation.Y +
                    relativeRotation.Z * relativeRotation.Z);
                float dot   = relativeRotation.X * Direction.X + relativeRotation.Y * Direction.Y + relativeRotation.Z * Direction.Z;
                float theta = (dot >= 0) ?
                              (2.0f * MathFunctions.ATan(sint2, cost2)) :                // if u points in direction of axis
                              (2.0f * MathFunctions.ATan(sint2, -cost2));                // if u points in opposite direction

                // the angle we get will be between 0..2*pi, but we want to return angles between -pi..pi
                if (theta > MathFunctions.PI)
                {
                    theta -= 2.0f * MathFunctions.PI;
                }

                //// the angle we've just extracted has the wrong sign
                //theta = -theta;

                return(theta);
            }
        public void SetTurnToPosition(Vec3 pos)
        {
            turnToPosition = pos;

            Vec3 diff = turnToPosition - Position;

            horizontalDirectionForUpdateRotation = MathFunctions.ATan(diff.Y, diff.X);

            //UpdateRotation();
        }
        private float CalculateAngleTo(Unit unit)
        {
            Vec3 dir = (unit.GetInterpolatedPosition() - Position);

            Radian unitAngle = (Rotation.ToAngles().Yaw) / -57.29578f;
            Radian needAngle = MathFunctions.ATan(dir.Y, dir.X);
            Radian diffAngle = needAngle - unitAngle;


            return(Math.Abs(diffAngle));
        }
 void UpdatePlatformerDemoLookDirection()
 {
     if (GameMap.Instance != null && GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo &&
         LastTickForceVector != Vec2.Zero)
     {
         if (Intellect != null && PlayerIntellect.Instance == Intellect)
         {
             float angle = MathFunctions.ATan(LastTickForceVector.Y, LastTickForceVector.X);
             PlayerIntellect.Instance.LookDirection = new SphereDir(angle, 0);
         }
     }
 }
Exemple #9
0
        void EnemyUnitTick(Entity entity)
        {
            Dynamic obj = (Dynamic)entity;

            Unit playerUnit = null;

            if (PlayerIntellect.Instance != null)
            {
                playerUnit = PlayerIntellect.Instance.ControlledObject;
            }

            if (playerUnit != null)
            {
                float playerDistance = (obj.Position - playerUnit.Position).Length();

                Vec3  diff  = playerUnit.Position - obj.Position;
                float angle = MathFunctions.ATan(diff.Y, diff.X);

                //Suicide
                bool  allowSuicide    = false;
                float suicideDistance = 3;

                if (playerUnit is Turret)
                {
                    allowSuicide = true;
                }

                if (allowSuicide && playerDistance < suicideDistance)
                {
                    obj.Die();

                    Dynamic dieObject = (Dynamic)Entities.Instance.Create("TurretDemo_MonsterSuicideObject", Map.Instance);
                    dieObject.Position = obj.Position;
                    dieObject.PostCreate();

                    dieObject.Die();

                    return;
                }
            }

            //Check outside map
            Bounds bounds = Map.Instance.InitialCollisionBounds;

            bounds.Expand(new Vec3(50, 50, 300));
            if (!bounds.IsContainsPoint(((MapObject)entity).Position))
            {
                entity.SetForDeletion(false);
            }
        }
Exemple #10
0
        // NH & KEEN - reworked the homing function for better accuracy
        private void MomentaryTurnToPositionUpdate(Vec3 turnToPosition)
        {
            if (targetBody != null)
            {
                turnToPosition = targetBody.Position;

                if (targetShape != null)
                {
                    turnToPosition += (targetShape.Position * targetBody.Rotation);
                }

                if (Type.HomingPrediction > 0.0f)
                {
                    float flyTime = (turnToPosition - Position).Length() / Type.Velocity;

                    turnToPosition += targetBody.LinearVelocity * flyTime * Type.HomingPrediction;
                }
            }

            Vec3 diff = (turnToPosition - Position);

            Degree horizontalAngle = new Radian(-MathFunctions.ATan(diff.Y, diff.X)).InDegrees();
            Degree verticalAngle   = new Radian(MathFunctions.ATan(diff.Z, diff.ToVec2().Length())).InDegrees();

            Quat collisionRotation = new Angles(0, 0, horizontalAngle).ToQuat();

            collisionRotation *= new Angles(0, verticalAngle, 0).ToQuat();

            Radian targetAngle = Quat.GetAngle(Rotation, collisionRotation);

            float PI = (float)Math.PI;

            if (targetAngle > PI)
            {
                targetAngle = (2 * PI) - targetAngle;
            }

            Radian maxTurnAbility = Type.HomingCorrection.InRadians() * TickDelta;

            if (targetAngle > maxTurnAbility)
            {
                float relativeCorrection = maxTurnAbility / targetAngle;

                Rotation = Quat.Slerp(Rotation, collisionRotation, relativeCorrection);
            }
            else
            {
                Rotation = collisionRotation;
            }
        }
Exemple #11
0
        void Server_TickSendWeaponVerticalAngleToClients()
        {
            Vec3  diff  = TurnToPosition - Position;
            float angle = -MathFunctions.ATan(diff.Z, diff.ToVec2().Length());

            MathFunctions.Clamp(ref angle, -MathFunctions.PI / 2, MathFunctions.PI / 2);

            if (Math.Abs(server_sentWeaponVerticalAngle - angle) > .01f)
            {
                Server_SendWeaponVerticalAngleToClients(EntitySystemWorld.Instance.RemoteEntityWorlds,
                                                        angle);
                server_sentWeaponVerticalAngle = angle;
            }
        }
Exemple #12
0
        public void SetLookDirection(Vec3 pos)
        {
            Vec2 diff = pos.ToVec2() - Position.ToVec2();

            if (diff == Vec2.Zero)
            {
                return;
            }

            Radian dir = MathFunctions.ATan(diff.Y, diff.X);

            float halfAngle = dir * 0.5f;
            Quat  rot       = new Quat(new Vec3(0, 0, MathFunctions.Sin(halfAngle)), MathFunctions.Cos(halfAngle));

            Rotation = rot;
        }
        private void GetFireParameters(out Vec3 pos, out Quat rot, out float speed)
        {
            Camera camera = RendererWorld.Instance.DefaultCamera;

            pos = catapult.Position + new Vec3(0, 0, .7f);

            Radian verticalAngle = new Degree(30).InRadians();

            rot   = Quat.Identity;
            speed = 0;

            if (catapultFiring)
            {
                Ray startRay = camera.GetCameraToViewportRay(catapultFiringMouseStartPosition);
                Ray ray      = camera.GetCameraToViewportRay(MousePosition);

                Plane plane = Plane.FromPointAndNormal(pos, Vec3.ZAxis);

                Vec3 startRayPos;
                if (!plane.RayIntersection(startRay, out startRayPos))
                {
                    //must never happen
                }

                Vec3 rayPos;
                if (!plane.RayIntersection(ray, out rayPos))
                {
                    //must never happen
                }

                Vec2 diff = rayPos.ToVec2() - startRayPos.ToVec2();

                Radian horizonalAngle = MathFunctions.ATan(diff.Y, diff.X) + MathFunctions.PI;

                SphereDir dir = new SphereDir(horizonalAngle, verticalAngle);
                rot = Quat.FromDirectionZAxisUp(dir.GetVector());

                float distance = diff.Length();

                //3 meters clamp
                MathFunctions.Clamp(ref distance, .001f, 3);

                speed = distance * 10;
            }
        }
Exemple #14
0
        public void SetForceFireRotationLookTo(Vec3 lookTo)
        {
            setForceFireRotation = true;

            Quat rot;

            {
                Vec3 diff = lookTo - GetFirePosition(false);

                float dirh     = MathFunctions.ATan(diff.Y, diff.X);
                float dirv     = -MathFunctions.ATan(diff.Z, diff.ToVec2().LengthFast());
                float halfdirh = dirh * .5f;
                rot = new Quat(new Vec3(0, 0, MathFunctions.Sin(halfdirh)),
                               MathFunctions.Cos(halfdirh));
                float halfdirv = dirv * .5f;
                rot *= new Quat(0, MathFunctions.Sin(halfdirv), 0, MathFunctions.Cos(halfdirv));
            }
            forceFireRotation = rot;
        }
Exemple #15
0
        private void CalculateThings()
        {
            Vec3 unitPos = this.Position;
            Vec3 unitDir = this.Rotation.GetForward();
            Vec3 needDir;

            needDir = TaskPosition - unitPos;
            Radian unitAngle = MathFunctions.ATan(unitDir.Y, unitDir.X);
            Radian needAngle = MathFunctions.ATan(needDir.Y, needDir.X);
            Radian diffAngle = needAngle - unitAngle;

            if (diffAngle < -MathFunctions.PI)
            {
                diffAngle = -MathFunctions.PI * 2;
            }
            if (diffAngle > MathFunctions.PI)
            {
                diffAngle = MathFunctions.PI * 2;
            }
            ZADiffAngle = diffAngle;
        }
        void MomentaryTurnToPositionUpdate(Vec3 turnToPosition)
        {
            if ((turnToPosition - Position).Length() < 4.0f)
            {
                Vec3 dir = (turnToPosition - Position).GetNormalize();
                turnToPosition += dir * 10f;
            }

            Vec3  diff = (turnToPosition - Position);
            Quat  collisionRotation;
            float distance = diff.LengthFast();

            Radian horizontalAngle = MathFunctions.ATan(diff.Y, diff.X);
            Radian verticalAngle   = MathFunctions.ATan(diff.Z, diff.ToVec2().Length());

            collisionRotation = new Angles(0, 0, -horizontalAngle.InDegrees()).ToQuat();

            collisionRotation *= new Angles(0, verticalAngle.InDegrees(), 0).ToQuat();

            Rotation = Quat.Slerp(Rotation, collisionRotation, Type.HomingCorrection);
        }
Exemple #17
0
        void TickUserForceToBall(float delta)
        {
            const float forceMultiplier = 700;

            Vec2 vec = Vec2.Zero;

            if (EngineApp.Instance.IsKeyPressed(EKeys.Left) || EngineApp.Instance.IsKeyPressed(EKeys.A))
            {
                vec.Y++;
            }
            if (EngineApp.Instance.IsKeyPressed(EKeys.Right) || EngineApp.Instance.IsKeyPressed(EKeys.D))
            {
                vec.Y--;
            }
            if (EngineApp.Instance.IsKeyPressed(EKeys.Up) || EngineApp.Instance.IsKeyPressed(EKeys.W))
            {
                vec.X++;
            }
            if (EngineApp.Instance.IsKeyPressed(EKeys.Down) || EngineApp.Instance.IsKeyPressed(EKeys.S))
            {
                vec.X--;
            }

            if (vec != Vec2.Zero)
            {
                vec.Normalize();

                //calculate force vector with considering camera orientation
                Vec2   diff         = ball.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();
                Vec2   forceVector2 = (rot * new Vec3(1, 0, 0)).ToVec2();
                Vec3   forceVector  = new Vec3(forceVector2.X, forceVector2.Y, 0);

                Body body = ball.PhysicsModel.Bodies[0];
                body.AddForce(ForceType.GlobalAtLocalPos, delta, forceVector * forceMultiplier, Vec3.Zero);
            }
        }
Exemple #18
0
        /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary>
        protected override void OnRender(Camera camera)
        {
            base.OnRender(camera);

            //no update in cubemap generation mode
            if (Map.Instance.CubemapGenerationMode)
            {
                return;
            }

            bool playerIntellectFPSCamera = false;
            {
                PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
                if (playerIntellect != null)
                {
                    playerIntellectFPSCamera = playerIntellect.FPSCamera;
                }
            }
            bool fpsCamera = playerIntellectFPSCamera && RendererWorld.Instance.DefaultCamera == camera;

            if (activeWeapon != null && GameMap.Instance.GameType != GameMap.GameTypes.TPSArcade)
            {
                //FPS mesh material
                activeWeapon.FPSMeshMaterialNameEnabled =
                    fpsCamera && !camera.IsForShadowMapGeneration();

                //update weapon vertical orientation
                if (activeWeaponAttachedObject.MapObject is Gun)
                {
                    //for guns
                    if (fpsCamera)
                    {
                        Vec3 p = camera.Position + camera.Rotation * Type.WeaponFPSAttachPosition;
                        Quat r = camera.Rotation;
                        Vec3 s = new Vec3(1, 1, 1);
                        activeWeaponAttachedObject.MapObject.SetTransform(p, r, s);
                        activeWeaponAttachedObject.MapObject.SetOldTransform(p, r, s);

                        //Vec3 diff = playerIntellect.LookDirection.GetVector();
                        //float dirV = -MathFunctions.ATan( diff.Z, diff.ToVec2().Length() );
                        //float halfDirV = dirV * .5f;
                        //Quat rot = new Quat( 0, MathFunctions.Sin( halfDirV ), 0,
                        //   MathFunctions.Cos( halfDirV ) );
                        //activeWeaponAttachedObject.RotationOffset = rot;
                        //activeWeaponAttachedObject.PositionOffset =
                        //   Type.FPSCameraOffset + Type.WeaponFPSAttachPosition * rot;
                    }
                    else
                    {
                        float dirV;

                        if (EntitySystemWorld.Instance.IsClientOnly())
                        {
                            //client specific
                            dirV = client_weaponVerticalAngle;
                        }
                        else
                        {
                            Vec3 diff = TurnToPosition - Position;
                            dirV = -MathFunctions.ATan(diff.Z, diff.ToVec2().Length());
                        }

                        float halfDirV = dirV * .5f;
                        Quat  rot      = new Quat(0, MathFunctions.Sin(halfDirV), 0,
                                                  MathFunctions.Cos(halfDirV));

                        activeWeaponAttachedObject.RotationOffset = rot;
                        activeWeaponAttachedObject.PositionOffset = Type.WeaponAttachPosition;
                    }
                }
                else
                {
                    //for melee weapons
                    activeWeaponAttachedObject.RotationOffset = Quat.Identity;
                    activeWeaponAttachedObject.PositionOffset = Vec3.Zero;
                }

                //no cast shadows from active weapon in the FPS mode
                foreach (MapObjectAttachedObject weaponAttachedObject in activeWeapon.AttachedObjects)
                {
                    MapObjectAttachedMesh weaponAttachedMesh = weaponAttachedObject as MapObjectAttachedMesh;
                    if (weaponAttachedMesh != null && weaponAttachedMesh.MeshObject != null)
                    {
                        if (weaponAttachedMesh.RemainingTime == 0)
                        {
                            weaponAttachedMesh.MeshObject.CastShadows = !fpsCamera;
                        }
                    }
                }
            }

            //only weapon visible in the FPS mode
            foreach (MapObjectAttachedObject attachedObject in AttachedObjects)
            {
                attachedObject.Visible = !fpsCamera || attachedObject == activeWeaponAttachedObject;
            }

            //no cast shadows in the FPS mode
            if (camera.IsForShadowMapGeneration() && playerIntellectFPSCamera)
            {
                foreach (MapObjectAttachedObject attachedObject in AttachedObjects)
                {
                    attachedObject.Visible = false;
                }
            }
        }
Exemple #19
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;
            }
        }
        private void UpdateMoveTaskControlKeys()
        {
            bool forward = false;
            //bool backward = false;
            bool left  = false;
            bool right = false;

            if (moveTaskEnabled)
            {
                //Vehicle specific

                Vec3 unitPos = ControlledObject.Position;
                Vec3 unitDir = ControlledObject.Rotation.GetForward();
                Vec3 needDir = moveTaskPosition - unitPos;

                Radian unitAngle = MathFunctions.ATan(unitDir.Y, unitDir.X);
                Radian needAngle = MathFunctions.ATan(needDir.Y, needDir.X);

                Radian diffAngle = needAngle - unitAngle;
                while (diffAngle < -MathFunctions.PI)
                {
                    diffAngle += MathFunctions.PI * 2;
                }
                while (diffAngle > MathFunctions.PI)
                {
                    diffAngle -= MathFunctions.PI * 2;
                }

                //!!!!!!! 10.0f
                if (Math.Abs(diffAngle) > new Degree(10.0f).InRadians())
                {
                    if (diffAngle > 0)
                    {
                        left = true;
                    }
                    else
                    {
                        right = true;
                    }
                }

                if (diffAngle > -MathFunctions.PI / 2 && diffAngle < MathFunctions.PI / 2)
                {
                    forward = true;
                }
            }

            if (forward)
            {
                ControlKeyPress(GameControlKeys.Forward, 1);
            }
            else
            {
                ControlKeyRelease(GameControlKeys.Forward);
            }

            //if( backward )
            //   ControlKeyPress( ControlKey.Backward );
            //else
            //   ControlKeyRelease( ControlKey.Backward );

            if (left)
            {
                ControlKeyPress(GameControlKeys.Left, 1);
            }
            else
            {
                ControlKeyRelease(GameControlKeys.Left);
            }

            if (right)
            {
                ControlKeyPress(GameControlKeys.Right, 1);
            }
            else
            {
                ControlKeyRelease(GameControlKeys.Right);
            }
        }
Exemple #21
0
        void TickMove()
        {
            //path find control
            {
                if (pathFindWaitTime != 0)
                {
                    pathFindWaitTime -= TickDelta;
                    if (pathFindWaitTime < 0)
                    {
                        pathFindWaitTime = 0;
                    }
                }

                if (pathFoundedToPosition != MovePosition.ToVec2() && pathFindWaitTime == 0)
                {
                    path.Clear();
                }

                if (path.Count == 0)
                {
                    if (pathFindWaitTime == 0)
                    {
                        if (DoPathFind())
                        {
                            pathFoundedToPosition = MovePosition.ToVec2();
                            pathFindWaitTime      = .5f;
                        }
                        else
                        {
                            pathFindWaitTime = 1.0f;
                        }
                    }
                }
            }

            if (path.Count == 0)
            {
                return;
            }

            //line movement to path[ 0 ]
            {
                Vec2 destPoint = path[0];

                Vec2 diff = destPoint - Position.ToVec2();

                if (diff == Vec2.Zero)
                {
                    path.RemoveAt(0);
                    return;
                }

                Radian dir = MathFunctions.ATan(diff.Y, diff.X);

                float halfAngle = dir * 0.5f;
                Quat  rot       = new Quat(new Vec3(0, 0, MathFunctions.Sin(halfAngle)),
                                           MathFunctions.Cos(halfAngle));
                Rotation = rot;

                Vec2 dirVector = diff.GetNormalize();
                Vec2 dirStep   = dirVector * (Type.MaxVelocity * TickDelta);

                Vec2 newPos = Position.ToVec2() + dirStep;

                if (Math.Abs(diff.X) <= Math.Abs(dirStep.X) && Math.Abs(diff.Y) <= Math.Abs(dirStep.Y))
                {
                    //unit at point
                    newPos = path[0];
                    path.RemoveAt(0);
                }

                GetNavigationSystem().RemoveObjectFromMotionMap(this);

                bool free;
                {
                    float radius     = Type.Radius;
                    Rect  targetRect = new Rect(newPos - new Vec2(radius, radius), newPos + new Vec2(radius, radius));
                    free = GetNavigationSystem().IsFreeInMapMotion(targetRect);
                }

                GetNavigationSystem().AddObjectToMotionMap(this);

                if (free)
                {
                    float newZ = GetNavigationSystem().GetMotionMapHeight(newPos) + Type.Height * .5f;
                    Position = new Vec3(newPos.X, newPos.Y, newZ);
                }
                else
                {
                    path.Clear();
                }
            }
        }
Exemple #22
0
        protected override void OnTick(float delta)
        {
            base.OnTick(delta);

            if (hudControl.Enable && GetRealCameraType() == CameraType.Top && !EngineConsole.Instance.Active)
            {
                //change cameraPosition
                if (Time > 2)
                {
                    //rotate vector
                    if (newAzimuthAngle != cameraDirection.Horizontal)
                    {
                        /*if (newAzimuthAngle > cameraDirection.Horizontal)
                         *  cameraDirection.Horizontal += angleToUpdate;
                         * else
                         *  cameraDirection.Horizontal -= angleToUpdate;*/

                        //cameraDirection.Horizontal = delta * (cameraDirection.Horizontal - newAzimuthAngle);

                        cameraDirection.Horizontal = newAzimuthAngle;
                    }

                    //move
                    Vec2 vector = Vec2.Zero;
                    if (MousePosition.X < .005f)
                    {
                        vector.X--;
                    }
                    if (MousePosition.X > 1.0f - .005f)
                    {
                        vector.X++;
                    }
                    if (MousePosition.Y < .005f)
                    {
                        vector.Y++;
                    }
                    if (MousePosition.Y > 1.0f - .005f)
                    {
                        vector.Y--;
                    }

                    if (vector != Vec2.Zero)
                    {
                        //rotate vector
                        float angle = MathFunctions.ATan(-vector.Y, vector.X) + cameraDirection.Horizontal;
                        vector = new Vec2(MathFunctions.Sin(angle), MathFunctions.Cos(angle));
                        Vec2 result = cameraPosition.ToVec2() + vector * delta * 30;

                        if (Map.Instance.InitialCollisionBounds.IsContainsPoint(new Vec3(result.X, result.Y, 0)))
                        {
                            cameraPosition = new Vec3(result.X, result.Y, 0);
                        }
                    }
                }
            }

            //GameControlsManager
            if (EntitySystemWorld.Instance.Simulation)
            {
                if (GetRealCameraType() != CameraType.Free && !IsCutSceneEnabled())
                {
                    GameControlsManager.Instance.DoTick(delta);
                }
            }
        }
        /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary>
        protected override void OnRender(Camera camera)
        {
            base.OnRender(camera);

            //get camera state
            bool playerIntellectFPSCamera = false;
            {
                PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
                if (playerIntellect != null)
                {
                    playerIntellectFPSCamera = playerIntellect.FPSCamera;
                }
            }
            bool fpsCamera          = playerIntellectFPSCamera && camera.Purpose == Camera.Purposes.MainCamera;
            bool mainCameraUpdating = SceneManager.Instance.CurrentUpdatingCamera.Purpose == Camera.Purposes.MainCamera;

            //update first person arms
            MapObjectAttachedMesh firstPersonArmsAttachedMesh =
                GetFirstAttachedObjectByAlias("firstPersonArms") as MapObjectAttachedMesh;

            if (firstPersonArmsAttachedMesh != null)
            {
                if (EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor && fpsCamera)
                {
                    UpdateFirstPersonArmsAttachedMesh(firstPersonArmsAttachedMesh, camera);
                }
            }

            //update weapon
            if (activeWeapon != null && GameMap.Instance.GameType != GameMap.GameTypes.TPSArcade &&
                GameMap.Instance.GameType != GameMap.GameTypes.PlatformerDemo)
            {
                //update weapon attached objects visibility depending camera type
                activeWeapon.UpdateTPSFPSCameraAttachedObjectsVisibility(fpsCamera);

                //update weapon position. Guns only.
                if (activeWeaponAttachedObject.MapObject is Gun)
                {
                    //guns
                    if (fpsCamera)
                    {
                        if (firstPersonArmsAttachedMesh != null)
                        {
                            Vec3 p;
                            Quat r;
                            Vec3 s;

                            string slotName = activeWeapon.Type.CharacterBoneSlotFirstPersonCamera;
                            if (!string.IsNullOrEmpty(slotName))
                            {
                                MapObjectAttachedMesh.MeshBoneSlot slot = GetBoneSlotFromAttachedMeshes(slotName);
                                if (slot != null)
                                {
                                    slot.GetGlobalTransform(out p, out r, out s);
                                }
                                else
                                {
                                    p = camera.Position;
                                    r = camera.Rotation;
                                    s = new Vec3(1, 1, 1);
                                }
                            }
                            else
                            {
                                p = camera.Position + camera.Rotation * activeWeapon.Type.FPSCameraAttachPosition;
                                r = camera.Rotation;
                                s = new Vec3(1, 1, 1);
                            }

                            activeWeaponAttachedObject.MapObject.SetTransform(p, r, s);
                            activeWeaponAttachedObject.MapObject.SetOldTransform(p, r, s);
                        }
                    }
                    else
                    {
                        //change active weapon position for non animated characters
                        if (activeWeaponAttachedObject.BoneSlot == null)
                        {
                            Vec3  diff     = TurnToPosition - Position;
                            float dirV     = -MathFunctions.ATan(diff.Z, diff.ToVec2().Length());
                            float halfDirV = dirV * .5f;
                            Quat  rot      = new Quat(0, MathFunctions.Sin(halfDirV), 0,
                                                      MathFunctions.Cos(halfDirV));

                            activeWeaponAttachedObject.RotationOffset = rot;
                            activeWeaponAttachedObject.PositionOffset = Type.NotAnimatedWeaponAttachPosition;
                        }
                    }
                }

                //no cast shadows from active weapon in the FPS mode
                foreach (MapObjectAttachedObject weaponAttachedObject in activeWeapon.AttachedObjects)
                {
                    MapObjectAttachedMesh weaponAttachedMesh = weaponAttachedObject as MapObjectAttachedMesh;
                    if (weaponAttachedMesh != null && weaponAttachedMesh.MeshObject != null)
                    {
                        if (weaponAttachedMesh.RemainingTime == 0)
                        {
                            weaponAttachedMesh.MeshObject.CastShadows = !fpsCamera;
                        }
                    }
                }
            }

            //change visibility of attached objects
            {
                foreach (MapObjectAttachedObject attachedObject in AttachedObjects)
                {
                    if (attachedObject == activeWeaponAttachedObject)
                    {
                        //attached weapon is always visible
                        attachedObject.Visible = true;
                    }
                    else if (attachedObject == firstPersonArmsAttachedMesh)
                    {
                        //first person arms is visible only for first person camera. The weapon is also must be activated.
                        attachedObject.Visible = fpsCamera && activeWeaponAttachedObject != null;
                    }
                    else
                    {
                        //hide attached objects for first person camera
                        attachedObject.Visible = !fpsCamera;
                    }
                }

                //hide shadows for first person camera mode
                if (playerIntellectFPSCamera && mainCameraUpdating && camera.Purpose == Camera.Purposes.ShadowMap)
                {
                    foreach (MapObjectAttachedObject attachedObject in AttachedObjects)
                    {
                        attachedObject.Visible = false;
                    }
                }
            }
        }
Exemple #24
0
        protected override void OnTick(float delta)
        {
            base.OnTick(delta);

            //If atop openly any window to not process
            if (IsPaused())
            {
                return;
            }

            if (!FreeCameraMouseRotating)
            {
                EngineApp.Instance.MouseRelativeMode = false;
            }

            bool activeConsole = EngineConsole.Instance != null && EngineConsole.Instance.Active;

            if (GetRealCameraType() == CameraType.Game && !activeConsole)
            {
                if (EngineApp.Instance.IsKeyPressed(EKeys.PageUp))
                {
                    cameraDistance -= delta * (cameraDistanceRange[1] - cameraDistanceRange[0]) / 10.0f;
                    if (cameraDistance < cameraDistanceRange[0])
                    {
                        cameraDistance = cameraDistanceRange[0];
                    }
                }

                if (EngineApp.Instance.IsKeyPressed(EKeys.PageDown))
                {
                    cameraDistance += delta * (cameraDistanceRange[1] - cameraDistanceRange[0]) / 10.0f;
                    if (cameraDistance > cameraDistanceRange[1])
                    {
                        cameraDistance = cameraDistanceRange[1];
                    }
                }

                //rtsCameraDirection

                if (EngineApp.Instance.IsKeyPressed(EKeys.Home))
                {
                    cameraDirection.Vertical += delta * (cameraAngleRange[1] - cameraAngleRange[0]) / 2;
                    if (cameraDirection.Vertical >= cameraAngleRange[1])
                    {
                        cameraDirection.Vertical = cameraAngleRange[1];
                    }
                }

                if (EngineApp.Instance.IsKeyPressed(EKeys.End))
                {
                    cameraDirection.Vertical -= delta * (cameraAngleRange[1] - cameraAngleRange[0]) / 2;
                    if (cameraDirection.Vertical < cameraAngleRange[0])
                    {
                        cameraDirection.Vertical = cameraAngleRange[0];
                    }
                }

                if (EngineApp.Instance.IsKeyPressed(EKeys.Q))
                {
                    cameraDirection.Horizontal += delta * 2;
                    if (cameraDirection.Horizontal >= MathFunctions.PI * 2)
                    {
                        cameraDirection.Horizontal -= MathFunctions.PI * 2;
                    }
                }

                if (EngineApp.Instance.IsKeyPressed(EKeys.E))
                {
                    cameraDirection.Horizontal -= delta * 2;
                    if (cameraDirection.Horizontal < 0)
                    {
                        cameraDirection.Horizontal += MathFunctions.PI * 2;
                    }
                }


                //change cameraPosition
                if (Time > 2)
                {
                    Vec2 vector = Vec2.Zero;

                    if (EngineApp.Instance.IsKeyPressed(EKeys.Left) ||
                        EngineApp.Instance.IsKeyPressed(EKeys.A) || MousePosition.X < .005f)
                    {
                        vector.X--;
                    }
                    if (EngineApp.Instance.IsKeyPressed(EKeys.Right) ||
                        EngineApp.Instance.IsKeyPressed(EKeys.D) || MousePosition.X > 1.0f - .005f)
                    {
                        vector.X++;
                    }
                    if (EngineApp.Instance.IsKeyPressed(EKeys.Up) ||
                        EngineApp.Instance.IsKeyPressed(EKeys.W) || MousePosition.Y < .005f)
                    {
                        vector.Y++;
                    }
                    if (EngineApp.Instance.IsKeyPressed(EKeys.Down) ||
                        EngineApp.Instance.IsKeyPressed(EKeys.S) || MousePosition.Y > 1.0f - .005f)
                    {
                        vector.Y--;
                    }

                    if (vector != Vec2.Zero)
                    {
                        //rotate vector
                        float angle = MathFunctions.ATan(-vector.Y, vector.X) +
                                      cameraDirection.Horizontal;
                        vector = new Vec2(MathFunctions.Sin(angle), MathFunctions.Cos(angle));

                        cameraPosition += vector * delta * 50;
                    }
                }
            }
        }
        private Vec2 GetMovementByControlKeys()
        {
            Vec2 localVector = Vec2.Zero;

            if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsDedicatedServer())
            {
                PlayerManager.ServerOrSingle_Player player = null;
                player = PlayerManager.Instance.ServerOrSingle_GetPlayer(Intellect);
                if (GameMap.Instance != null && player.Intellect == Intellect)                  //PlayerIntellect.Instance == Intellect)
                {
                    localVector.X -= Intellect.GetControlKeyStrength(GameControlKeys.Forward);  // +this.Type.SpeedForward;
                    localVector.X += Intellect.GetControlKeyStrength(GameControlKeys.Backward); // +this.Type.SpeedBackward;
                    localVector.Y -= Intellect.GetControlKeyStrength(GameControlKeys.Left);     // +this.Type.SpeedLeft;
                    localVector.Y += Intellect.GetControlKeyStrength(GameControlKeys.Right);    // +this.Type.SpeedRight;

                    if (localVector != Vec2.Zero)
                    {
                        Vec2   diff     = Position.ToVec2() - TurnToPosition.ToVec2();;// *Rotation.GetForward().ToVec2();//RendererWorld.Instance.DefaultCamera.Position.ToVec2();
                        Degree angle    = new Radian(MathFunctions.ATan(diff.Y, diff.X));
                        Degree vecAngle = new Radian(MathFunctions.ATan(-localVector.Y, localVector.X));
                        Quat   rot      = new Angles(0, 0, vecAngle - angle).ToQuat();
                        Vec2   vector   = (rot * new Vec3(1, 0, 0)).ToVec2();
                        return(vector);
                    }
                    else
                    {
                        return(Vec2.Zero);
                    }
                }
                return(Vec2.Zero);
            }
            else if (EntitySystemWorld.Instance.IsSingle())
            {
                if (GameMap.Instance != null && PlayerIntellect.Instance == Intellect)
                {
                    localVector.X -= Intellect.GetControlKeyStrength(GameControlKeys.Forward);  // +this.Type.SpeedForward;
                    localVector.X += Intellect.GetControlKeyStrength(GameControlKeys.Backward); // +this.Type.SpeedBackward;
                    localVector.Y -= Intellect.GetControlKeyStrength(GameControlKeys.Left);     // +this.Type.SpeedLeft;
                    localVector.Y += Intellect.GetControlKeyStrength(GameControlKeys.Right);    // +this.Type.SpeedRight;

                    if (localVector != Vec2.Zero)
                    {
                        Vec2   diff     = Position.ToVec2() - TurnToPosition.ToVec2();;// *Rotation.GetForward().ToVec2();//RendererWorld.Instance.DefaultCamera.Position.ToVec2();
                        Degree angle    = new Radian(MathFunctions.ATan(diff.Y, diff.X));
                        Degree vecAngle = new Radian(MathFunctions.ATan(-localVector.Y, localVector.X));
                        Quat   rot      = new Angles(0, 0, vecAngle - angle).ToQuat();
                        Vec2   vector   = (rot * new Vec3(1, 0, 0)).ToVec2();
                        return(vector);
                    }
                    else
                    {
                        return(Vec2.Zero);
                    }
                }
                return(Vec2.Zero);
            }
            return(Vec2.Zero);
            ////    if (localVector != Vec2.Zero)
            ////    {
            ////        localVector.Normalize();

            ////        //calculate force vector with considering camera orientation
            ////        Vec2 diff = Position.ToVec2() - RendererWorld.Instance.DefaultCamera.Position.ToVec2();
            ////        //new Vec3( RendererWorld.Instance.DefaultCamera.Position.X,RendererWorld.Instance.DefaultCamera.Position.Y, Damager_Ball_Player.Position.Z);
            ////        //diff.Z += this.Type.BallRadius;

            ////        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();

            ////        Vec2 forceVector2 = (rot * new Vec3(1, 0, 0)).ToVec2();

            ////        Vec2 forceVector = new Vec2(forceVector2.X, forceVector2.Y);

            ////        return forceVector;
            ////    }
            ////    else return vec;
            ////}
            ////else
            ////    return vec;
        }
        private void EnemyUnitTick(Entity entity)
        {
            Dynamic obj = (Dynamic)entity;

            Unit playerUnit = null;

            if (PlayerIntellect.Instance != null)
            {
                playerUnit = PlayerIntellect.Instance.ControlledObject;
            }

            if (playerUnit != null)
            {
                float playerDistance = (obj.Position - playerUnit.Position).Length();

                Vec3  diff  = playerUnit.Position - obj.Position;
                float angle = MathFunctions.ATan(diff.Y, diff.X);

                //Change rotation
                //temp. fake
                Aircraft aircraft = entity as Aircraft;
                if (aircraft != null)
                {
                    obj.PhysicsModel.Bodies[0].Rotation =
                        new Angles(0, 0, -MathFunctions.RadToDeg(angle)).ToQuat();
                    //obj.Rotation = new Angles(0,0, -MathFunctions.RadToDeg(angle)).ToQuat();

                    aircraft.FlyHeight = 10;

                    if (playerDistance < 20)
                    {
                        aircraft.FlyHeight = playerUnit.Position.Z;
                    }
                }

                //Suicide
                bool  allowSuicide    = false;
                float suicideDistance = 3;

                if (playerUnit is Turret)
                {
                    allowSuicide = true;
                }

                if (aircraft != null)
                {
                    allowSuicide = true;
                }

                if (allowSuicide && playerDistance < suicideDistance)
                {
                    obj.Die();

                    Dynamic dieObject = (Dynamic)Entities.Instance.Create("TurretDemo_MonsterSuicideObject", Map.Instance);
                    dieObject.Position = obj.Position;
                    dieObject.PostCreate();

                    dieObject.Die();

                    return;
                }
            }

            //Check outside map
            Bounds bounds = Map.Instance.InitialCollisionBounds;

            bounds.Expand(new Vec3(50, 50, 300));
            if (!bounds.IsContainsPoint(((MapObject)entity).Position))
            {
                entity.SetForDeletion(false);
            }
        }
        Vec2 GetMovementVectorByControlKeys()
        {
            //use specified force move vector
            if (forceMoveVectorTimer != 0)
            {
                return(forceMoveVector);
            }

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

                Vec2 localVector = Vec2.Zero;
                localVector.X += Intellect.GetControlKeyStrength(GameControlKeys.Forward);
                localVector.X -= Intellect.GetControlKeyStrength(GameControlKeys.Backward);
                localVector.Y += Intellect.GetControlKeyStrength(GameControlKeys.Left);
                localVector.Y -= Intellect.GetControlKeyStrength(GameControlKeys.Right);

                if (localVector != Vec2.Zero)
                {
                    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(-localVector.Y, localVector.X));
                    Quat   rot      = new Angles(0, 0, vecAngle - angle).ToQuat();
                    Vec2   vector   = (rot * new Vec3(1, 0, 0)).ToVec2();
                    return(vector);
                }
                else
                {
                    return(Vec2.Zero);
                }
            }

            //PlatformerDemo specific
            if (GameMap.Instance != null && GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo &&
                PlayerIntellect.Instance == Intellect)
            {
                Vec2 vector = Vec2.Zero;
                vector.X -= Intellect.GetControlKeyStrength(GameControlKeys.Left);
                vector.X += Intellect.GetControlKeyStrength(GameControlKeys.Right);
                return(vector);
            }

            //default behaviour
            {
                Vec2 localVector = Vec2.Zero;
                localVector.X += Intellect.GetControlKeyStrength(GameControlKeys.Forward);
                localVector.X -= Intellect.GetControlKeyStrength(GameControlKeys.Backward);
                localVector.Y += Intellect.GetControlKeyStrength(GameControlKeys.Left);
                localVector.Y -= Intellect.GetControlKeyStrength(GameControlKeys.Right);

                Vec2 vector = (new Vec3(localVector.X, localVector.Y, 0) * Rotation).ToVec2();
                if (vector != Vec2.Zero)
                {
                    float length = vector.Length();
                    if (length > 1)
                    {
                        vector /= length;
                    }
                }
                return(vector);
            }
        }
Exemple #28
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;
            }
        }
Exemple #29
0
        private void TickChassis()
        {
            bool onGround = leftTrack.onGround || rightTrack.onGround;

            float leftTrackThrottle  = 0;
            float rightTrackThrottle = 0;

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

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

                float left = Intellect.GetControlKeyStrength(GameControlKeys.Left);
                leftTrackThrottle  -= left * 2;
                rightTrackThrottle += left * 2;

                float right = Intellect.GetControlKeyStrength(GameControlKeys.Right);
                leftTrackThrottle  += right * 2;
                rightTrackThrottle -= right * 2;

                MathFunctions.Clamp(ref leftTrackThrottle, -1, 1);
                MathFunctions.Clamp(ref rightTrackThrottle, -1, 1);
            }

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

            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 ? Type.DriveForwardForce : Type.BrakeForce;
                    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 = localLinearVelocity.X > 0 ? Type.BrakeForce : 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 ? Type.DriveForwardForce : Type.BrakeForce;
                    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 = localLinearVelocity.X > 0 ? Type.BrakeForce : 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 = onGround && leftTrackThrottle == 0 && rightTrackThrottle == 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 : 1;
            }
            else
            {
                linearDamping = .15f;
            }
            chassisBody.LinearDamping = linearDamping + slopeLinearDampingAddition;

            //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 #30
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));
                }
            }
        }