-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCC_CharacterController.cs
More file actions
103 lines (78 loc) · 2.42 KB
/
Copy pathRCC_CharacterController.cs
File metadata and controls
103 lines (78 loc) · 2.42 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//----------------------------------------------
// Realistic Car Controller
//
// Copyright © 2014 - 2017 BoneCracker Games
// http://www.bonecrackergames.com
// Buğra Özdoğanlar
//
//----------------------------------------------
using UnityEngine;
using System.Collections;
/// <summary>
/// Animates Driver Sofie (Credits to 3DMaesen). Simply feeds floats and bools of Sofie's animator component.
/// </summary>
[AddComponentMenu("BoneCracker Games/Realistic Car Controller/Misc/RCC Animator Controller")]
public class RCC_CharacterController : MonoBehaviour {
private RCC_CarControllerV3 carController;
private Rigidbody carRigid;
public Animator animator;
// String parameters of animator.
public string driverSteeringParameter;
public string driverShiftingGearParameter;
public string driverDangerParameter;
public string driverReversingParameter;
// Inputs for feeding animator.
public float steerInput = 0f;
public float directionInput = 0f;
public bool reversing = false;
public float impactInput = 0f;
public float gearInput = 0f;
void Start () {
if(!animator)
animator = GetComponentInChildren<Animator>();
carController = GetComponent<RCC_CarControllerV3>();
carRigid = GetComponent<Rigidbody>();
}
void Update () {
steerInput = Mathf.Lerp(steerInput, carController.steerInput, Time.deltaTime * 5f);
directionInput = carRigid.transform.InverseTransformDirection(carRigid.velocity).z;
impactInput -= Time.deltaTime * 5f;
if(impactInput < 0)
impactInput = 0f;
if(impactInput > 1)
impactInput = 1f;
if(directionInput <= -2f)
reversing = true;
else if(directionInput > -1f)
reversing = false;
if(carController.changingGear)
gearInput = 1f;
else
gearInput -= Time.deltaTime * 5f;
if(gearInput < 0)
gearInput = 0f;
if(gearInput > 1)
gearInput = 1f;
if(!reversing){
animator.SetBool(driverReversingParameter, false);
}else{
animator.SetBool(driverReversingParameter, true);
}
if(impactInput > .5f){
animator.SetBool(driverDangerParameter, true);
}else{
animator.SetBool(driverDangerParameter, false);
}
if(gearInput > .5f){
animator.SetBool(driverShiftingGearParameter, true);
}else{
animator.SetBool(driverShiftingGearParameter, false);
}
animator.SetFloat(driverSteeringParameter, steerInput);
}
void OnCollisionEnter(Collision col){
if(col.relativeVelocity.magnitude < 2.5f)
return;
impactInput = 1f;
}
}