Files
racesm/Assets/Scripts/Car Controller.cs
2024-03-22 11:34:56 +01:00

28 lines
799 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 = 10000000f;
public float steeringAngle = 30f;
void Update()
{
// Motor input
float motorInput = Input.GetAxis("Vertical");
frontLeftWheel.motorTorque = motorInput * motorForce;
frontRightWheel.motorTorque = motorInput * motorForce;
// Steering input
float steeringInput = Input.GetAxis("Horizontal");
frontLeftWheel.steerAngle = steeringInput * steeringAngle;
frontRightWheel.steerAngle = steeringInput * steeringAngle;
// Move camera
}
}