Первый коммит
This commit is contained in:
19
Assets/Scripts/Car/CarController.cs
Normal file
19
Assets/Scripts/Car/CarController.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CarController : MonoBehaviour
|
||||
{
|
||||
#region Wheels
|
||||
|
||||
//
|
||||
public Transform FrontLeftWheelTransform;
|
||||
public Transform FrontRightWheelTransform;
|
||||
public Transform RearLeftWheelTransform;
|
||||
public Transform RearRightWheelTransform;
|
||||
public Transform[] ExtraRearWheelTransform;
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
11
Assets/Scripts/Car/CarController.cs.meta
Normal file
11
Assets/Scripts/Car/CarController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1a1526faad80734d845657393bb0289
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
15
Assets/Scripts/Car/Core.cs
Normal file
15
Assets/Scripts/Car/Core.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Core : MonoBehaviour
|
||||
{
|
||||
#region Create WheelColliders
|
||||
public void CreateWheelColliders(CarController carController)
|
||||
{
|
||||
List <Transform> allWheelModels = new List <Transform> ();
|
||||
allWheelModels.Add (carController.FrontLeftWheelTransform);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
11
Assets/Scripts/Car/Core.cs.meta
Normal file
11
Assets/Scripts/Car/Core.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e1829d0d5b4c4144bf629b553d45a72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
55
Assets/Scripts/Car/EasySuspension.cs
Normal file
55
Assets/Scripts/Car/EasySuspension.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteInEditMode()]
|
||||
public class EasySuspension : MonoBehaviour {
|
||||
[Range(0, 20)]
|
||||
public float naturalFrequency = 10;
|
||||
|
||||
[Range(0, 3)]
|
||||
public float dampingRatio = 0.8f;
|
||||
|
||||
[Range(-1, 1)]
|
||||
public float forceShift = 0.03f;
|
||||
|
||||
public bool setSuspensionDistance = true;
|
||||
|
||||
void Update () {
|
||||
// work out the stiffness and damper parameters based on the better spring model
|
||||
foreach (WheelCollider wc in GetComponentsInChildren<WheelCollider>()) {
|
||||
JointSpring spring = wc.suspensionSpring;
|
||||
|
||||
spring.spring = Mathf.Pow(Mathf.Sqrt(wc.sprungMass) * naturalFrequency, 2);
|
||||
spring.damper = 2 * dampingRatio * Mathf.Sqrt(spring.spring * wc.sprungMass);
|
||||
|
||||
wc.suspensionSpring = spring;
|
||||
|
||||
Vector3 wheelRelativeBody = transform.InverseTransformPoint(wc.transform.position);
|
||||
float distance = GetComponent<Rigidbody>().centerOfMass.y - wheelRelativeBody.y + wc.radius;
|
||||
|
||||
wc.forceAppPointDistance = distance - forceShift;
|
||||
|
||||
// the following line makes sure the spring force at maximum droop is exactly zero
|
||||
if (spring.targetPosition > 0 && setSuspensionDistance)
|
||||
wc.suspensionDistance = wc.sprungMass * Physics.gravity.magnitude / (spring.targetPosition * spring.spring);
|
||||
}
|
||||
}
|
||||
|
||||
// uncomment OnGUI to observe how parameters change
|
||||
|
||||
/*
|
||||
public void OnGUI()
|
||||
{
|
||||
foreach (WheelCollider wc in GetComponentsInChildren<WheelCollider>()) {
|
||||
GUILayout.Label (string.Format("{0} sprung: {1}, k: {2}, d: {3}", wc.name, wc.sprungMass, wc.suspensionSpring.spring, wc.suspensionSpring.damper));
|
||||
}
|
||||
|
||||
var rb = GetComponent<Rigidbody> ();
|
||||
|
||||
GUILayout.Label ("Inertia: " + rb.inertiaTensor);
|
||||
GUILayout.Label ("Mass: " + rb.mass);
|
||||
GUILayout.Label ("Center: " + rb.centerOfMass);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
11
Assets/Scripts/Car/EasySuspension.cs.meta
Normal file
11
Assets/Scripts/Car/EasySuspension.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3089a8970aaa5f24194f910c4b8428ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
23
Assets/Scripts/Car/Finish.cs
Normal file
23
Assets/Scripts/Car/Finish.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
|
||||
class Finish : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject Effects;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Effects.SetActive(false);
|
||||
}
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.gameObject.tag == "Player 1" || other.gameObject.tag == "Player 2")
|
||||
{
|
||||
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
Effects.SetActive(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Car/Finish.cs.meta
Normal file
11
Assets/Scripts/Car/Finish.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 740b084a5b2918d479603cbf4fb1ac29
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
63
Assets/Scripts/Car/RearWheelDrive.cs
Normal file
63
Assets/Scripts/Car/RearWheelDrive.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class RearWheelDrive : MonoBehaviour {
|
||||
|
||||
private WheelCollider[] wheels;
|
||||
|
||||
public float maxAngle = 30;
|
||||
public float maxTorque = 300;
|
||||
public GameObject wheelShape;
|
||||
|
||||
// here we find all the WheelColliders down in the hierarchy
|
||||
public void Start()
|
||||
{
|
||||
wheels = GetComponentsInChildren<WheelCollider>();
|
||||
|
||||
for (int i = 0; i < wheels.Length; ++i)
|
||||
{
|
||||
var wheel = wheels [i];
|
||||
|
||||
// create wheel shapes only when needed
|
||||
if (wheelShape != null)
|
||||
{
|
||||
var ws = GameObject.Instantiate (wheelShape);
|
||||
ws.transform.parent = wheel.transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this is a really simple approach to updating wheels
|
||||
// here we simulate a rear wheel drive car and assume that the car is perfectly symmetric at local zero
|
||||
// this helps us to figure our which wheels are front ones and which are rear
|
||||
public void Update()
|
||||
{
|
||||
float angle = maxAngle * Input.GetAxis("Horizontal");
|
||||
float torque = maxTorque * Input.GetAxis("Vertical");
|
||||
|
||||
foreach (WheelCollider wheel in wheels)
|
||||
{
|
||||
// a simple car where front wheels steer while rear ones drive
|
||||
if (wheel.transform.localPosition.z > 0)
|
||||
wheel.steerAngle = angle;
|
||||
|
||||
if (wheel.transform.localPosition.z < 0)
|
||||
wheel.motorTorque = torque;
|
||||
|
||||
// update visual wheels if any
|
||||
if (wheelShape)
|
||||
{
|
||||
Quaternion q;
|
||||
Vector3 p;
|
||||
wheel.GetWorldPose (out p, out q);
|
||||
|
||||
// assume that the only child of the wheelcollider is the wheel shape
|
||||
Transform shapeTransform = wheel.transform.GetChild (0);
|
||||
shapeTransform.position = p;
|
||||
shapeTransform.rotation = q;
|
||||
shapeTransform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Car/RearWheelDrive.cs.meta
Normal file
11
Assets/Scripts/Car/RearWheelDrive.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a315b19833d58ff49abead1689c81f47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user