Files
racesm/Assets/Scripts/Car Controller.cs
2024-03-25 15:56:53 +01:00

26 lines
769 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarController : MonoBehaviour
{
public WheelCollider frontLeftWheel, frontRightWheel;
public WheelCollider rearLeftWheel, rearRightWheel;
public float motorForce = 1000f;
public float steeringAngle = 30f;
void Update()
{
// Motor input
float motorInput = Input.GetAxis("Vertical");
rearLeftWheel.motorTorque = motorInput * motorForce;
rearRightWheel.motorTorque = motorInput * motorForce;
// Steering input
float steeringInput = Input.GetAxis("Horizontal");
frontLeftWheel.steerAngle = steeringInput * steeringAngle;
frontRightWheel.steerAngle = steeringInput * steeringAngle;
}
}