blob: 679db09fbed818f7df3fe3a0f5c63390c2968b43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
using UnityEngine;
public class WheelVisualizer : MonoBehaviour
{
private Rigidbody rig;
public float spinAmount;
public float inputVelocityAmount;
public float inputReturnVelocityAmount;
public float inputFriction;
private GenericInputHandler input;
private float inputVelocity;
private void Start()
{
rig = GetComponentInParent<Rigidbody>();
input = GetComponentInParent<GenericInputHandler>();
}
private void FixedUpdate()
{
inputVelocity *= inputFriction;
}
private void Update()
{
inputVelocity += input.inputDirection.x;
inputVelocity -= inputVelocity * inputReturnVelocityAmount * Time.deltaTime;
base.transform.localRotation = Quaternion.Euler(0f, inputVelocity * inputVelocityAmount, 0f);
base.transform.GetChild(0).Rotate(Vector3.right * spinAmount * Time.deltaTime * rig.transform.InverseTransformDirection(rig.velocity).z, Space.Self);
}
}
|