Merge branch 'master' of ooftooft.net:Racesm

This commit is contained in:
2024-04-05 12:31:07 +02:00
5 changed files with 189 additions and 8 deletions

View 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");
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 43a3b21977ed2c64b8d62ca5013ab914
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c9672ffa7e21bf41b27f35da94be659
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: