Files
CarTest/Assets/Scripts/Wheel.cs

35 lines
1.1 KiB
C#
Raw Normal View History

2023-06-14 14:35:32 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Wheel
{
[SerializeField] private WheelCollider collider;
[SerializeField] private Transform wheel;
[SerializeField] private float wheelSize = 15; //default size change to what the actual size is
public float GetWheelRPM(){ return collider.rpm; } //return the wheels current rpm
public void ApplySteerAngle(float steerAngle){ //apply steer angle to wheel to rotate
collider.steerAngle = steerAngle;
}
public void ApplyBrakeForce(float brakeForce){ //apply brake force to the wheel
collider.brakeTorque = brakeForce;
}
public void ApplyAcceleration(float acceleration){ //apply acceleration value to the wheel
collider.motorTorque = acceleration;
}
public void UpdateWheel(){ //rotates the wheel when the car is moving
Vector3 position;
Quaternion rotation;
collider.GetWorldPose(out position, out rotation);
wheel.position = position;
wheel.rotation = rotation;
}
}