123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SimpleBikeController : MonoBehaviour
- {
- public WheelCollider[] steeringColliders;
- public WheelCollider[] motorColliders;
- public float factorTorque = 0.5f;
- public float factorSteer = 0.2f;
- public float maxMotorTorque = 100f;
-
- private float torque = 0f;
- private float steer = 0f;
- private void OnGUI()
- {
- GUI.Box(new Rect(10 ,10, 80, 40), $"Torque: {torque}\nSteer: {steer}");
- }
- // Update is called once per frame
- void Update()
- {
- torque = Input.GetAxis("Vertical") * factorTorque;
- steer = Input.GetAxis("Horizontal") * factorSteer;
- }
- private void FixedUpdate()
- {
- foreach (var c in steeringColliders)
- {
- c.steerAngle = steer;
- }
- foreach (var c in motorColliders)
- {
- c.motorTorque = Mathf.Clamp(torque, 0 ,maxMotorTorque);
- }
- }
- }
|