コード例 #1
0
 private void WriteToModel(float engineRot, GearState currentGear)
 {
     //データ書き込み処理
     mDataUiCarModel.CurrentSpeed.Value       = ConvertUnits.MpsToKmph(mVehicleMove.GetSpeed);
     mDataUiCarModel.CurrentEnginePower.Value = mEngine.GetEngineRpm(engineRot);
     mDataUiCarModel.CurrentGear.Value        = currentGear;
 }
コード例 #2
0
    /// <summary>
    /// 停止時から素早い加速をする処理
    /// </summary>
    /// <param name="accel"></param>
    /// <param name="engineSpeed"></param>
    /// <returns></returns>
    public float AccelarateStart(float accel, float engineSpeed, GearState currentGear)
    {
        if (currentGear == GearState.NEUTRAL)
        {
            return(engineSpeed);
        }
        if (currentGear == GearState.REVERSE)
        {
            return(engineSpeed);
        }
        //アクセルを踏んでないとき返す
        if (accel < 0.1f)
        {
            return(engineSpeed);
        }
        if (engineSpeed > 5.0f)
        {
            return(engineSpeed);
        }
        if (engineSpeed < 0.0f)
        {
            return(engineSpeed);
        }

        engineSpeed += mEngineSettings.StartDash;
        return(engineSpeed);
    }
コード例 #3
0
ファイル: Engine.cs プロジェクト: Naot-Cocoa/AbsoluteSpeed
    /// <summary>
    /// 回転数を増やす処理
    /// エンジン回転数を返す
    /// ■accel:accelのInput
    /// </summary>
    public float UpdateRotateEngine(float accel, float brake, GearState currentGear)
    {
        if (mGearManager.GetGearManager.IsMT)//mt時
        {
            if ((currentGear != GearState.REVERSE) && (mEngineSpeed > 0.0f))
            {
                mEngineSpeed = mRigidbody.velocity.magnitude;
            }

            //エンジン回転数の計算処理
            mEngineSpeed = mEngineCalc.CalcEngineSpeed(mEngineSpeed, accel);
            //スタートダッシュの回転数加工処理
            mEngineSpeed = mEngineCalc.AccelarateStart(accel, mEngineSpeed, currentGear);
            //ブレーキ処理
            mEngineSpeed = mEngineCalc.Brake(brake, mEngineSpeed);
            return(mEngineSpeed);
        }
        else
        {
            if (currentGear != GearState.REVERSE)
            {
                mEngineSpeed = mRigidbody.velocity.magnitude;
            }
            mEngineSpeed = mEngineCalc.CalcEngineSpeedAT(mEngineSpeed, accel, brake);
            mEngineSpeed = mEngineCalc.AccelarateStart(accel, mEngineSpeed, currentGear);
            mEngineSpeed = mEngineCalc.BrakeAT(brake, mEngineSpeed);
            return(mEngineSpeed);
        }
    }
コード例 #4
0
ファイル: Program.cs プロジェクト: tstites14/SE-ShipControl
        private void CalibrateGearState(List <IMyLandingGear> gear)
        {
            bool gearLocked = gear.Any(item =>
            {
                return(item.LockMode == LandingGearMode.Locked);
            });
            bool pistonsExtended = pistons.Any(item =>
            {
                return(item.CurrentPosition == item.HighestPosition);
            });
            bool isTransitioning = pistons.Any(item =>
            {
                return(item.CurrentPosition != item.LowestPosition &&
                       item.CurrentPosition != item.HighestPosition);
            });

            if (gearLocked)
            {
                gearState = GearState.Open;
            }
            else if (!pistonsExtended)
            {
                gearState = GearState.Closed;
            }
            else if (isTransitioning)
            {
                gearState = GearState.Transition;
            }
        }
コード例 #5
0
ファイル: LandingGear.cs プロジェクト: cydert/MusicCloud
        // Update is called once per frame
        private void Update()
        {
            /*
             * if (m_State == GearState.Lowered && m_Plane.Altitude > raiseAtAltitude && m_Rigidbody.velocity.y > 0)
             * {
             *  m_State = GearState.Raised;
             * }
             *
             * if (m_State == GearState.Raised && m_Plane.Altitude < lowerAtAltitude && m_Rigidbody.velocity.y < 0)
             * {
             *  m_State = GearState.Lowered;
             * }
             */
            //ギアUp/Down
            if (Input.GetButtonDown("Gear"))
            {
                if (m_State == GearState.Lowered)
                {
                    m_State = GearState.Raised;
                }
                else if (m_State == GearState.Raised)
                {
                    m_State = GearState.Lowered;
                }
                m_Animator.SetInteger("GearState", (int)m_State);   //アニメーション再生
            }


            // set the parameter on the animator controller to trigger the appropriate animation
        }
コード例 #6
0
    public static JSONObject GearStateToJSON(GearState state)
    {
        JSONObject jSONObject = new JSONObject(JSONObject.Type.OBJECT);

        jSONObject.AddField("Level", state.Level.Value);
        return(jSONObject);
    }
コード例 #7
0
    public static GearState JSONToGearState(JSONObject jobj)
    {
        GearState gearState = new GearState();

        gearState.Level.Value = jobj.asInt("Level", () => 0);
        return(gearState);
    }
コード例 #8
0
    private void Start()
    {
        /*エンジンの回転から前に力を加える処理
         * 車体を進行方向に向かせる処理*/
        (this).FixedUpdateAsObservable()
        .Subscribe(_ =>
        {
            if (mGameSceneManager.SceneState != SceneState.GAME)
            {
                return;
            }

            float accel           = mPlayerInput.Accel.Value;
            float steer           = mPlayerInput.Hundle.Value;
            float brake           = mPlayerInput.Brake.Value;
            GearState currentGear = mPlayerInput.GetCurrentGear.Value;

            print("Brake : " + brake);

            //姿勢制御処理
            mAirRide.FixBalance(mRigidbody.velocity);
            //進行方向修正処理
            mDirFix.FixDirection(accel, steer);//傾く
            //ジャンプ中はブレーキとハンドルは制御させない
            if (!mAirRide.IsGround)
            {
                brake = 0.0f;
                steer = 0.0f;
            }

            RaycastHit hitInfo = new RaycastHit();
            mAIPenaltyRay.ForwardBoxCast(out hitInfo);
            //aiと正面方向が衝突したときaccel無効にする
            //アクセルを切っても速度は結構生きているかも?

            steer = SteeringScript.IgnoreLSteer(mWallHitCheck.LHit, steer);
            steer = SteeringScript.IgnoreRSteer(mWallHitCheck.RHit, steer);
            //ペナルティ処理
            mEngine.GiveWallPenalty(mWallHitCheck.LOrRHit);
            mEngine.GiveDriftPenalty(mVehicleMove.GetWheelState == WheelState.DRIFT, transform.forward);
            bool aiPenalty = (hitInfo.transform != null) && hitInfo.transform.gameObject.CompareTag(ConstString.Tag.AI);
            mEngine.GiveAiPenalty(aiPenalty);

            float engineRot = mEngine.UpdateRotateEngine(accel, brake, currentGear);

            steer = SteeringScript.InverseSteer(engineRot, steer);
            //車を動かす処理
            mVehicleMove.UpdateMove(engineRot, steer, brake, mAirRide.IsGround);

            //データ書き込み処理
            WriteToModel(engineRot, currentGear);
        });

        this.OnCollisionStayAsObservable().Subscribe(_ =>
        {
            mEngine.OnCollisionStay();
        });
    }
コード例 #9
0
ファイル: Gear.cs プロジェクト: DuCNiKo/SWUM
 public Gear(GearType gearType, JobType job, GearState state, GearElementary elementary, TierType tier, LevelType level)
     : base (ItemType.Gear, tier, level)
 {
     if (gearType == GearType.Undefined) throw new ArgumentException("The gear type is undefined.", nameof(gearType));
     if (job == JobType.Undefined) throw new ArgumentException("The job is undefined.", nameof(job));
     if (state == GearState.Undefined) throw new ArgumentException("The gear state is undefined.", nameof(state));
     Elementary = elementary;
     State = state;
     GearType = gearType;
     Job = job;
 }
コード例 #10
0
 //コンストラクタ
 public EngineRpmCalculator(GearParam gearParam, IReadOnlyReactiveProperty <GearState> gearState)
 {
     gearState
     .Buffer(2, 1)
     .Subscribe(x =>
     {
         mMaxSpeed    = gearParam.GetGearData(x.Last()).MaxSpeed;
         mGearState   = x.Last();
         mMaxPreSpeed = gearParam.GetGearData(x.First()).MaxSpeed;
     });
 }
コード例 #11
0
    void DropTP()
    {
        currState = GearState.ExtenderNeutral;
        anim.SetBool("hasTP", false);
        hasTP = false;
        // Random point.
        Vector2 point       = Random.insideUnitCircle * range;
        Vector3 newLocation = new Vector3(point.x, -2, point.y);

        newLocation          += transform.position - transform.TransformDirection(Vector3.forward) * range;
        TP.transform.position = newLocation;
        TP.SetActive(true);
    }
コード例 #12
0
    public GearRunner(int gearIndex)
    {
        SceneLoader instance = SceneLoader.Instance;

        GearIndex = gearIndex;
        Config    = PersistentSingleton <Economies> .Instance.Gears[gearIndex];
        GearState orCreateGearState = GearStateFactory.GetOrCreateGearState(gearIndex);

        Level = orCreateGearState.Level;
        Level.Skip(1).Subscribe(delegate
        {
            if (PersistentSingleton <GameAnalytics> .Instance != null)
            {
                PersistentSingleton <GameAnalytics> .Instance.GearUpgraded.Value = this;
            }
        }).AddTo(instance);
        SalvageRelicAmount = (from lvl in Level
                              select GetSalvageAmount(GearIndex, lvl)).TakeUntilDestroy(instance).ToReactiveProperty();
        SalvageGemCost = SalvageRelicAmount.Select(SalvageRelicsToGems.Evaluate).ToReactiveProperty();
        Unlocked       = (from lvl in Level
                          select lvl >= 1).TakeUntilDestroy(instance).ToReactiveProperty();
        (from pair in Unlocked.Pairwise()
         where pair.Current && !pair.Previous
         select pair).Subscribe(delegate
        {
            PlayerData.Instance.LifetimeGears.Value++;
        }).AddTo(instance);
        SalvageAvailable   = PlayerData.Instance.Gems.CombineLatest(SalvageGemCost, (int gems, int cost) => gems >= cost).TakeUntilDestroy(instance).ToReactiveProperty();
        UpgradeRequirement = (from lvl in Level
                              select Singleton <EconomyHelpers> .Instance.GetGearUpgradeCost(GearIndex, lvl)).TakeUntilDestroy(instance).ToReactiveProperty();
        MaxLevelReached = (from level in Level
                           select level >= Config.MaxLevel).TakeUntilDestroy(instance).ToReactiveProperty();
        UniRx.IObservable <CraftingRequirement> left = GearCollectionRunner.CreateBlocksObservable();
        UpgradeAvailable = left.CombineLatest(UpgradeRequirement, (CraftingRequirement have, CraftingRequirement req) => have.Satisfies(req)).CombineLatest(MaxLevelReached, (bool sat, bool max) => sat && !max).TakeUntilDestroy(instance)
                           .ToReactiveProperty();
        UpgradeGemCost           = left.CombineLatest(UpgradeRequirement, (CraftingRequirement have, CraftingRequirement req) => Singleton <EconomyHelpers> .Instance.GetCraftingGemCost(have, req)).TakeUntilDestroy(instance).ToReactiveProperty();
        UpgradeAvailableWithGems = (from comb in UpgradeGemCost.CombineLatest(PlayerData.Instance.Gems, (int cost, int gems) => new
        {
            cost,
            gems
        })
                                    select(comb.cost <= comb.gems) ? true : false).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        UniRx.IObservable <CraftingRequirement> left2 = GearCollectionRunner.CreateAfterPrestigeBlocksObservable();
        UpgradeAfterPrestigeAvailable = left2.CombineLatest(UpgradeRequirement, (CraftingRequirement have, CraftingRequirement req) => have.Satisfies(req)).CombineLatest(MaxLevelReached, (bool sat, bool max) => sat && !max).TakeUntilDestroy(instance)
                                        .ToReactiveProperty();
        Boost1Amount = Observable.Return(Config.Boost1.Mult.Amount).CombineLatest(CreateGearBonusObservable(Config.Boost1.Mult.BonusType, Config.Boost1.LevelUpAmount), (float sum, Func <float, float> f) => f(sum)).TakeUntilDestroy(instance)
                       .ToReactiveProperty();
        Boost2Amount = Observable.Return(Config.Boost2.Mult.Amount).CombineLatest(CreateGearBonusObservable(Config.Boost2.Mult.BonusType, Config.Boost2.LevelUpAmount), (float sum, Func <float, float> f) => f(sum)).TakeUntilDestroy(instance)
                       .ToReactiveProperty();
    }
コード例 #13
0
        // Update is called once per frame
        private void Update()
        {
            if (m_State == GearState.Lowered && m_Plane.Altitude > raiseAtAltitude && m_Rigidbody.velocity.y > 0)
            {
                m_State = GearState.Raised;
            }

            if (m_State == GearState.Raised && m_Plane.Altitude < lowerAtAltitude && m_Rigidbody.velocity.y < 0)
            {
                m_State = GearState.Lowered;
            }

            m_Animator.SetInteger("GearState", (int) m_State);				// Wysyła parametr do AnimatorController
        }
コード例 #14
0
 //コンストラクタ
 public EngineRpmCalculator(GearParam gearParam, IReadOnlyReactiveProperty <GearState> gearState)
 {
     gearState
     .Buffer(2, 1)
     .Subscribe(x =>
     {
         //現在のギアに設定されている最高速度
         mMaxSpeed = gearParam.GetGearData(x.Last()).MaxSpeed;
         //現在のギアステート
         mGearState = x.Last();
         //ひとつ前のギアに設定されている最高速度
         mMaxPreSpeed = gearParam.GetGearData(x.First()).MaxSpeed;
     });
 }
コード例 #15
0
        // Update is called once per frame
        private void Update()
        {
            if (m_State == GearState.Lowered && m_Plane.Altitude > raiseAtAltitude && m_Rigidbody.velocity.y > 0)
            {
                m_State = GearState.Raised;
            }

            if (m_State == GearState.Raised && m_Plane.Altitude < lowerAtAltitude && m_Rigidbody.velocity.y < 0)
            {
                m_State = GearState.Lowered;
            }

            // set the parameter on the animator controller to trigger the appropriate animation
            m_Animator.SetInteger("GearState", (int)m_State);
        }
コード例 #16
0
    // Update is called once per frame
    void Update()
    {
        if (state == GearState.Lowered && plane.Altitude > raiseAtAltitude && GetComponent <Rigidbody>().velocity.y > 0)
        {
            state = GearState.Raised;
        }

        if (state == GearState.Raised && plane.Altitude < lowerAtAltitude && GetComponent <Rigidbody>().velocity.y < 0)
        {
            state = GearState.Lowered;
        }

        // set the parameter on the animator controller to trigger the appropriate animation
        animator.SetInteger("GearState", (int)state);
    }
コード例 #17
0
ファイル: LandingGear.cs プロジェクト: nynnejc/snowmanland
        // Update is called once per frame
        private void Update()
        {
            if (state == GearState.Lowered && plane.Altitude > raiseAtAltitude && rigidbody.velocity.y > 0)
            {
                state = GearState.Raised;
            }

            if (state == GearState.Raised && plane.Altitude < lowerAtAltitude && rigidbody.velocity.y < 0)
            {
                state = GearState.Lowered;
            }

            // set the parameter on the animator controller to trigger the appropriate animation
            animator.SetInteger("GearState", (int) state);
        }
コード例 #18
0
        private void UpdateGearPicture(PictureBox pb, GearState state)
        {
            switch (state)
            {
            case GearState.LOCKDOWN:
                pb.Image = Properties.Resources.gear2_extracted;
                break;

            case GearState.LOCKUP:
                pb.Image = Properties.Resources.gear2_retracted;
                break;

            case GearState.MOVING:
                pb.Image = Properties.Resources.gear2_moving;
                break;
            }
        }
コード例 #19
0
        // Update is called once per frame
        private void Update()
        {
            if (Input.GetKey(KeyCode.G))
            {
                if (m_State == GearState.Lowered)
                {
                    m_State = GearState.Raised;
                }
                else if (m_State == GearState.Raised)
                {
                    m_State = GearState.Lowered;
                }
            }

            // set the parameter on the animator controller to trigger the appropriate animation
            m_Animator.SetInteger("GearState", (int)m_State);
        }
コード例 #20
0
    /// <summary>
    /// 表示用のエンジン回転数を微調整したい場合に使用する。
    /// GetCoeff()のせいでエンジン回転数が最大まで達しない場合、かける値を大きくすることで
    /// 達するようにする
    /// </summary>
    /// <param name="gearState"></param>
    /// <returns></returns>
    private float GetInnerMaxRot(GearState gearState)
    {
        switch (gearState)
        {
        case GearState.FIRST: { return(9000); }

        case GearState.SECOND: { return(10000); }

        case GearState.THIRD: { return(10000); }

        case GearState.FOURTH: { return(10000); }

        case GearState.FIFTH: { return(10000); }

        case GearState.SIXTH: { return(10000); }

        default: return(10000);
        }
    }
コード例 #21
0
 private void Update()
 {
     if (SceneManager.GetActiveScene().buildIndex == 1)
     {
         if (m_State == GearState.Lowered && m_Plane.Altitude > raiseAtAltitude && m_Rigidbody.velocity.y > 0)
         {
             m_State = GearState.Raised;
         }
         if (m_State == GearState.Raised && m_Plane.Altitude < lowerAtAltitude && m_Rigidbody.velocity.y < 0)
         {
             m_State = GearState.Lowered;
         }
     }
     else if (SceneManager.GetActiveScene().buildIndex >= 2)
     {
         m_State = GearState.Raised;
     }
     m_Animator.SetInteger("GearState", (int)m_State);
 }
コード例 #22
0
    /// <summary>
    /// 表示用のエンジン回転数を微調整したい場合に使用する。
    /// ギア変更時に回転数の上下具合を調節できる。
    /// </summary>
    /// <param name="gearState"></param>
    /// <returns></returns>
    private float GetCoeff(GearState gearState)
    {
        switch (gearState)
        {
        case GearState.FIRST: { return(0.9f); }

        case GearState.SECOND: { return(0.9f); }

        case GearState.THIRD: { return(0.9f); }

        case GearState.FOURTH: { return(0.9f); }

        case GearState.FIFTH: { return(0.9f); }

        case GearState.SIXTH: { return(0.9f); }

        default: return(1.0f);
        }
    }
コード例 #23
0
    private int mNumberFontSize = 60;   // 数字フォントサイズ

    /// <summary>
    /// UIを更新
    /// </summary>
    /// <param name="currentState"> 現在のギア </param>
    public void UiUpdate(GearState currentState)
    {
        //Stateをintに変換(この時点でステートの値と表示する値の差異を埋める)
        int i = (int)currentState + mDifferenceValue;

        //その後stringへ変換
        if (i == 0)
        {
            ChangeFont("N", mAlphabetFont, mAlphabetFontSize);
        }
        else if (i == -1)
        {
            ChangeFont("R", mAlphabetFont, mAlphabetFontSize);
        }
        else
        {
            ChangeFont(i.ToString(), mNumberFont, mNumberFontSize);
        }

        //変更の反映
        mUiTextComponent.text = mUiCurrentText;
    }
コード例 #24
0
ファイル: Engine.cs プロジェクト: Naot-Cocoa/AbsoluteSpeed
    public Engine(EngineSpeedCalc engineCalc, Rigidbody rigidbody, IGearManageable input, IReadOnlyReactiveProperty <GearState> gear)
    {
        mEngineCalc  = engineCalc;
        mRigidbody   = rigidbody;
        mGearManager = input;

        gear
        .Buffer(2, 1)
        .Subscribe(x =>
        {
            //現在のギアデータ
            GearState currentGear = x.Last();
            //1つ前のギアデータ
            GearState preGear = x.First();


            //atの時ギアが下がった時に速度が少し下がる処理
            //mtの時度外視
            if (input.GetGearManager.IsMT)
            {
                return;
            }
            //Rの時は度外視
            if (currentGear == GearState.REVERSE)
            {
                return;
            }
            if (preGear == GearState.REVERSE)
            {
                return;
            }
            //ギアが下げられた場合
            if ((int)currentGear < (int)preGear)
            {
                mEngineSpeed -= 5.0f;
            }
        });
    }
コード例 #25
0
    IEnumerator Grab()
    {
        isGrabbing = true;
        anim.SetBool("isGrabbing", true);

        RaycastHit hit;

        //if (Physics.Raycast(transform.position, cam.transform.TransformDirection(Vector3.forward), out hit, range))
        if (Physics.SphereCast(transform.position, 1f, cam.transform.TransformDirection(Vector3.forward), out hit, range))
        {
            if (hit.collider != null)
            {
                if (hit.collider.gameObject.layer == LayerMask.NameToLayer("tp_layer"))
                {
                    currState = GearState.ExtenderHold;
                    anim.SetBool("hitTP", true);
                    anim.SetBool("hasTP", true);
                    // I feel this is awkward and not done right...!
                    hasTP = true;
                    TP    = hit.collider.gameObject;
                    TP.SetActive(false);
                }
                else if (hit.collider.gameObject.layer == LayerMask.NameToLayer("infected_layer"))
                {
                    hit.collider.gameObject.GetComponent <InfectedBehaviour>().StartCoroutine("IsHit");
                }
            }
        }
        else
        {
            // Miss. We'd put the embarassing audio here...if we had any.
        }
        yield return(new WaitForSeconds(0.5f));

        anim.SetBool("hitTP", false);
        isGrabbing = false;
        anim.SetBool("isGrabbing", false);
    }
コード例 #26
0
 /// <summary>
 /// 現在のギアのステートに合ったギアのデータを取得する
 /// </summary>
 /// <param name="gearState"></param>
 /// <returns></returns>
 public GearData GetGearData(GearState gearState)
 {
     return(mGearDataBase.FirstOrDefault(value => value.Gear == gearState));
 }
コード例 #27
0
 /// <summary>
 /// ギアのUIを反映させる処理
 /// </summary>
 /// <param name="currentState">更新するステート</param>
 public void GearDataUpdate(GearState currentState)
 {
     mCurrentGear.Value = currentState;
 }
        void Process(float delta_t)
        {
            double temp;
            double delta_rpm;
            double current_gear_ratio = 0.0;
            double brake_force;
            double percent_rpm;
            double turn_rate;
            bool   shift_up;
            bool   shift_down;
            double delta_psi;
            Vector gravity = new Vector(0.0f, 0.0f, 32.0f);

            wheel_angle = wheel_pos * wheel_max_angle;

            wheel[(int)WhichWheel.LeftFront].RelHeading  = wheel_angle;
            wheel[(int)WhichWheel.RightFront].RelHeading = wheel_angle;

            double sine_wheel = Math.Sin(wheel_angle);

            turn_rate = (sine_wheel * velocity.X / wheel_track) / 10.0f;
//			Debug.WriteLine( "sine_wheel=" + sine_wheel + " turn rate=" + turn_rate);

            if (wheel[(int)WhichWheel.LeftFront].sliding && wheel[(int)WhichWheel.RightFront].sliding)
            {
//				turn_rate = 0.0f;
            }

            attitude_rate.Psi = turn_rate;

            delta_psi = turn_rate * delta_t;

            centripedal_accel = (float)(2.0 * velocity.X * Math.Sin(delta_psi)) / delta_t;

            wheel_rpm = 60.0f * velocity.X / (Math.PI * wheel_diameter);

            rolling_resistance = 0.00696f * (float)Math.Abs(velocity.X);

            drag = 0.5f * drag_coeff * frontal_area * air_density * Math.Abs(velocity.X * velocity.X);

            brake_force = brake * 32.0;  // max braking 1G

            if (mph < 0.0)               // braking force opposes movement
            {
                brake_force *= -1.0;
            }

            if (wheel[(int)WhichWheel.LeftFront].sliding && wheel[(int)WhichWheel.RightFront].sliding &&
                wheel[(int)WhichWheel.RightRear].sliding && wheel[(int)WhichWheel.RightRear].sliding)
            {
                brake_force = 0.0f;
            }

            percent_rpm = engine_rpm / max_rpm;

            switch (gear)
            {
            case GearState.Park:
                if (mph > 1.0 || mph < -1.0)
                {
                    brake_force = 32.0;
                }
                else
                {
                    velocity.SetX(0.0f);
                }
                auto_gear = GearState.Park;
                break;

            case GearState.Reverse:
                auto_gear = GearState.Reverse;
                break;

            case GearState.Neutral:
                auto_gear = GearState.Neutral;
                break;

            case GearState.Drive:
                shift_up   = false;
                shift_down = false;
                if ((percent_rpm > 0.8 && auto_gear < GearState.Drive) ||
                    (percent_rpm > 0.1 && auto_gear == GearState.Neutral))
                {
                    shift_up = true;
                }
                if (percent_rpm < 0.4 && auto_gear >= GearState.FirstGear)
                {
                    shift_down = true;
                }
                switch (auto_gear)
                {
                case GearState.Neutral:
                    if (shift_up)
                    {
                        auto_gear = GearState.FirstGear;
                    }
                    break;

                case GearState.Drive:
                    if (shift_down)
                    {
                        auto_gear = GearState.ThirdGear;
                    }
                    break;

                case GearState.FirstGear:
                    if (shift_up)
                    {
                        auto_gear = GearState.SecondGear;
                    }
                    else if (shift_down)
                    {
                        auto_gear = GearState.Neutral;
                    }
                    break;

                case GearState.SecondGear:
                    if (shift_up)
                    {
                        auto_gear = GearState.ThirdGear;
                    }
                    else if (shift_down)
                    {
                        auto_gear = GearState.FirstGear;
                    }
                    break;

                case GearState.ThirdGear:
                    if (shift_up)
                    {
                        auto_gear = GearState.Drive;
                    }
                    else if (shift_down)
                    {
                        auto_gear = GearState.SecondGear;
                    }
                    break;
                }
                break;

            case GearState.FirstGear:
                auto_gear = GearState.FirstGear;
                break;

            case GearState.SecondGear:
                auto_gear = GearState.SecondGear;
                break;

            case GearState.ThirdGear:
                auto_gear = GearState.ThirdGear;
                break;
            }
            current_gear_ratio = gear_ratio[(int)auto_gear];

            if (running && target_rpm < idle_rpm)
            {
                target_rpm = idle_rpm;
            }
            else if (!running)
            {
                target_rpm = 0.0f;
            }
            else
            {
                target_rpm = idle_rpm + throttle * (max_rpm - idle_rpm);
            }
            delta_rpm = target_rpm - engine_rpm;
            if (delta_rpm > 3000.0f)
            {
                delta_rpm = 3000.0f;
            }
            else if (delta_rpm < -3000.0f)
            {
                delta_rpm = -3000.0f;
            }
            if (delta_rpm < 1.0f && delta_rpm > -1.0f)
            {
                delta_rpm = 0.0f;
            }
            engine_rpm += (delta_rpm * delta_t);
            if (auto_gear == GearState.Neutral || gear == GearState.Park)
            {
                eng_torque = 0.0;
            }
            else
            {
                eng_torque = torque_curve.Interpolate(percent_rpm * 100.0) * max_engine_torque;
            }

            engine_loss = Math.Max(((engine_rpm / 20) * (engine_rpm / 20) + 45), 0.0);

            brake_torque = brake_force * mass;

            temp = (eng_torque - engine_loss);

            if (temp < 0.0 && Math.Abs(mph) < 0.1)
            {
                temp = 0.0;
            }

            if (current_gear_ratio != 0.0)
            {
                wheel_force = temp;
            }
            else
            {
                wheel_force = 0.0f;
            }

            if ((drag + rolling_resistance) > wheel_force)
            {
                wheel_force = drag + rolling_resistance;
            }
            net_force = wheel_force - drag - rolling_resistance;
//Debug.WriteLine("wheel force=" + wheel_force.ToString() + " drag=" + drag + " rolling resist=" + rolling_resistance);

            if (gear == GearState.Reverse)
            {
                net_force *= -1.0f;                      // force in reverse is in opposite direction
            }

            ground_slope.RotateEtoA(gravity);
            body_gravity = gravity;

            if (gear != GearState.Park)
            {
                double net_accel = net_force / mass;       // covert to an accel
                net_accel     -= brake_force;
                acceleration.X = net_accel;                // + body_gravity.X;
//				Debug.WriteLine("Accel X=" + acceleration.X.ToString() + " body grav X=" + body_gravity.X.ToString()+
//					" net force= " + net_force.ToString());
//				Debug.WriteLine("ground slope=" + ground_slope.ThetaAsDegrees().ToString());
            }
            acceleration.Z -= body_gravity.Z;

            if (velocity.X < (delta_t * brake_force) && velocity.X > (delta_t * -brake_force))
            {
                mph            = 0.0f;
                velocity.X     = 0.0;
                acceleration.X = 0.0;
                brake_force    = 0.0;
            }

            if (auto_gear == GearState.Neutral || gear == GearState.Park)
            {
                temp = idle_rpm + (max_rpm - idle_rpm) * throttle;
            }
            else
            {
                temp = velocity.X * current_gear_ratio;
            }

            if (temp >= (idle_rpm * 0.9f))
            {
                if (temp > max_rpm)
                {
                    target_rpm = max_rpm;
                }
                else
                {
                    target_rpm = temp;
                }
            }
            else
            {
                target_rpm = idle_rpm;
            }

            CalcWeightTransfer();

            ProcessWheels(delta_t);

            ProcessAttitude(delta_t);

            IntegratePosition(delta_t);
        }
 public void SetGearRatio(GearState state, float ratio)
 {
     gear_ratio[(int)state] = ratio;
 }
        public void Reset()
        {
            wheel_max_angle     = 0.69813170079773183076947630739545;         // 40 degrees
            idle_rpm            = 700.0f;
            max_rpm             = 7000.0f;
            engine_rpm          = 0.0f;
            attitude.Theta      = 0.0f;
            attitude.Phi        = 0.0f;
            attitude.Psi        = 0.0f;
            attitude_rate.Theta = 0.0;
            attitude_rate.Phi   = 0.0;
            attitude_rate.Psi   = 0.0;
            position.X          = 0.0;
            position.Y          = 0.0;
            position.Z          = 0.0;
            velocity.X          = 0.0;                  // body velocity
            velocity.Y          = 0.0;                  // body velocity
            velocity.Z          = 0.0;                  // body velocity
            acceleration.X      = 0.0;                  // body accelerations
            acceleration.Y      = 0.0;                  // body accelerations
            acceleration.Z      = 0.0;                  // body accelerations
            cg_height           = -1.0;
            wheel_base          = 5.0;
            wheel_track         = 8.0;
            weight      = 2000.0;
            WheelRadius = 0.25;
            wheel[(int)WhichWheel.LeftFront].offset.Set(wheel_track / 2.0f, -wheel_base / 2.0f, +cg_height + wheel[(int)WhichWheel.LeftFront].radius);
            wheel[(int)WhichWheel.RightFront].offset.Set(wheel_track / 2.0f, wheel_base / 2.0f, +cg_height + wheel[(int)WhichWheel.LeftFront].radius);
            wheel[(int)WhichWheel.LeftRear].offset.Set(-wheel_track / 2.0f, -wheel_base / 2.0f, +cg_height + wheel[(int)WhichWheel.LeftFront].radius);
            wheel[(int)WhichWheel.RightRear].offset.Set(-wheel_track / 2.0f, wheel_base / 2.0f, +cg_height + wheel[(int)WhichWheel.LeftFront].radius);
            for (int i = 0; i < 4; i++)
            {
                wheel[i].StaticWeightOverWheel = weight / 4.0;
            }
            weight_distribution = 0.5f;
            front_weight        = weight * (1.0 - weight_distribution);
            back_weight         = weight * weight_distribution;
            wheel_pos           = 0.0f;
            throttle            = 0.0f;
            brake              = 0.0f;
            engine_rpm         = 0.0f;
            wheel_rpm          = 0.0f;
            wheel_force        = 0.0f;
            net_force          = 0.0f;
            mph                = 0.0f;
            drag               = 0.0f;
            rolling_resistance = 0.0f;
            eng_torque         = 0.0f;
            brake_torque       = 0.0f;
            engine_loss        = 0.0f;
            air_density        = 0.068;
            drag_coeff         = 0.004f;
            frontal_area       = 20.0f;
            mass               = weight * 0.031080950172;                               // in slugs
            inverse_mass       = 1.0 / mass;
            running            = true;
            front_wheel_drive  = false;
            gear               = GearState.Drive;
            gear_ratio[(int)GearState.Park]       = 0.0f;
            gear_ratio[(int)GearState.Reverse]    = -80.0f;
            gear_ratio[(int)GearState.Neutral]    = 0.0f;
            gear_ratio[(int)GearState.Drive]      = 45.0f;
            gear_ratio[(int)GearState.FirstGear]  = 70.0f;
            gear_ratio[(int)GearState.SecondGear] = 50.0f;
            gear_ratio[(int)GearState.ThirdGear]  = 30.0f;
            ignition_state    = IgnitionState.IgnitionOn;
            max_engine_torque = engine_horsepower * 255.00f;

            if (front_wheel_drive)
            {
                wheel[(int)WhichWheel.LeftFront].drive_wheel  = true;
                wheel[(int)WhichWheel.RightFront].drive_wheel = true;
                wheel[(int)WhichWheel.LeftRear].drive_wheel   = false;
                wheel[(int)WhichWheel.RightRear].drive_wheel  = false;
            }
            else
            {
                wheel[(int)WhichWheel.LeftFront].drive_wheel  = false;
                wheel[(int)WhichWheel.RightFront].drive_wheel = false;
                wheel[(int)WhichWheel.LeftRear].drive_wheel   = true;
                wheel[(int)WhichWheel.RightRear].drive_wheel  = true;
            }
        }
コード例 #31
0
 /// <summary>
 /// ギアのUIに反映する値の更新処理
 /// </summary>
 /// <param name="currentGear">更新される現在のギア(何速か)</param>
 public void GearUpdate(GearState currentGear)
 {
     mCurrentGearState.Value = currentGear;
 }
コード例 #32
0
 // Start is called before the first frame update
 void Start()
 {
     currState = GearState.ExtenderNeutral;
     //anim = GetComponent<Animator>();
 }