12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using UnityEngine;
- public class KeyboardBikeController : MonoBehaviour
- {
- private BicycleController bicycleController;
- public float torqueIncreasePerSecond = 10f;
- public float brakeTorqueIncreasePerSecond = 20f;
- public float leaningAngleIncreasePerSecond = 2f;
- public float steeringAngleIncreasePerSecond = 2.5f;
- public float maxMotorTorque = 400f;
- public float maxBrakeTorque = 600f;
- public float maxLeaningAngle = 35f;
- public float maxSteeringAngle = 70f;
- private void Start()
- {
- bicycleController = GetComponent<BicycleController>();
- }
- private void Update()
- {
- if (Input.GetKey(KeyCode.T))
- {
- bicycleController.CurrentBrakeTorque = 0f;
- bicycleController.CurrentMotorTorque += torqueIncreasePerSecond * Time.deltaTime;
- }
- else if (Input.GetKeyUp(KeyCode.T))
- {
- bicycleController.CurrentMotorTorque = 0f;
- }
- if (Input.GetKey(KeyCode.G))
- {
- bicycleController.CurrentMotorTorque = 0f;
- bicycleController.CurrentBrakeTorque += brakeTorqueIncreasePerSecond * Time.deltaTime;
- }
- else if (Input.GetKeyUp(KeyCode.G))
- {
- bicycleController.CurrentBrakeTorque = 0f;
- }
- if (Input.GetKey(KeyCode.F))
- {
- bicycleController.CurrentSteerAngle -= steeringAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.H))
- {
- bicycleController.CurrentSteerAngle += steeringAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKeyUp(KeyCode.F) || Input.GetKeyUp(KeyCode.H))
- {
- bicycleController.CurrentSteerAngle = 0f;
- }
- if (Input.GetKey(KeyCode.R))
- {
- bicycleController.CurrentLeaningAngle -= leaningAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.Z))
- {
- bicycleController.CurrentLeaningAngle += leaningAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKeyUp(KeyCode.R) || Input.GetKeyUp(KeyCode.Z))
- {
- bicycleController.CurrentLeaningAngle = 0f;
- }
- }
- }
|