Merge branch 'master' of ooftooft.net:Racesm
This commit is contained in:
17
Assets/Scripts/InputController.cs
Normal file
17
Assets/Scripts/InputController.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class InputController : MonoBehaviour
|
||||
{
|
||||
public float Horizontal { get; private set; }
|
||||
public float Vertical { get; private set; }
|
||||
public float Brake { get; private set; }
|
||||
|
||||
void Update()
|
||||
{
|
||||
Horizontal = Input.GetAxis("Horizontal");
|
||||
Vertical = Input.GetAxis("Vertical");
|
||||
Brake = Input.GetAxis("Jump");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/InputController.cs.meta
Normal file
11
Assets/Scripts/InputController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43a3b21977ed2c64b8d62ca5013ab914
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
54
Assets/Scripts/VehichleControl.cs
Normal file
54
Assets/Scripts/VehichleControl.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class VehichleControl : MonoBehaviour
|
||||
{
|
||||
public InputController InputCtrl;
|
||||
[Tooltip("Set ref in order of FL, FR, RL, RR")]
|
||||
public WheelCollider[] WheelColliders;
|
||||
|
||||
[Tooltip("Set ref of wheel meshes in order of FL, FR, RL, RR")]
|
||||
public Transform[] Wheels;
|
||||
|
||||
public Transform CenterOfMass;
|
||||
|
||||
public int Force;
|
||||
public int Angle;
|
||||
public int BrakeForce;
|
||||
|
||||
private void Drive()
|
||||
{
|
||||
WheelColliders[0].motorTorque = WheelColliders[1].motorTorque = InputCtrl.Vertical * Force;
|
||||
}
|
||||
|
||||
private void Steer()
|
||||
{
|
||||
WheelColliders[0].steerAngle = WheelColliders[1].steerAngle = InputCtrl.Horizontal * Angle;
|
||||
}
|
||||
|
||||
private void Brake()
|
||||
{
|
||||
WheelColliders[0].brakeTorque = WheelColliders[1].brakeTorque = InputCtrl.Brake * BrakeForce;
|
||||
}
|
||||
|
||||
private void UpdateWheelMovements()
|
||||
{
|
||||
for (var i = 0; i < Wheels.Length; i++)
|
||||
{
|
||||
Vector3 pos;
|
||||
Quaternion rot;
|
||||
WheelColliders[i].GetWorldPose(out pos, out rot);
|
||||
Wheels[i].transform.position = pos;
|
||||
Wheels[i].transform.rotation = rot;
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Steer();
|
||||
Drive();
|
||||
Brake();
|
||||
UpdateWheelMovements();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/VehichleControl.cs.meta
Normal file
11
Assets/Scripts/VehichleControl.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c9672ffa7e21bf41b27f35da94be659
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user