12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SphereBikeController : MonoBehaviour
- {
- public GameObject frontCollider;
- public GameObject rearCollider;
- public float factorRps = 0.5f;
- public float factorSteer = 0.2f;
- public float maxRps = 4f;
- private Transform frontTransform;
- private Transform rearTransform;
- public GameObject bike;
- private Rigidbody rb;
- private Transform bt;
- private float rps = 0f;
- private float steer = 0f;
- private void Start()
- {
- frontTransform = frontCollider.transform;
- rearTransform = rearCollider.transform;
- bt = bike.transform;
- rb = bike.GetComponent<Rigidbody>();
-
- }
- private void OnGUI()
- {
- GUI.Box(new Rect(10, 10, 80, 40), $"Rps: {rps}\nSteer: {steer}");
- }
- // Update is called once per frame
- void Update()
- {
- rps = Input.GetAxis("Vertical") * factorRps;
- steer = Input.GetAxis("Horizontal") * factorSteer;
- }
- private void FixedUpdate()
- {
- rb.velocity = bt.forward * 2;
- rearTransform.RotateAround(rearTransform.position, rearTransform.right, rps*Time.fixedDeltaTime*360f);
- }
- }
|