28 lines
799 B
C#
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
|
|
}
|
|
}
|