1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using UnityEngine;
- public class KeyboardBikeController : MonoBehaviour
- {
- private BicycleController bicycleController;
- public bool steer = true;
- public bool lean = true;
- public bool accelerate = true;
- 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 (accelerate)
- {
- 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 (steer)
- {
- 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 (lean)
- {
- 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;
- }
- }
- }
- }
|