You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.3 KiB
33 lines
1.3 KiB
using UnityEngine; |
|
using System.Collections; |
|
|
|
public class WheelAlignment : MonoBehaviour { |
|
|
|
public WheelCollider CorrespondingCollider; |
|
public bool itsTank; |
|
private float RotationValue = 0.0f; |
|
|
|
void Update() |
|
{ |
|
RaycastHit hit; |
|
var ColliderCenterPoint = CorrespondingCollider.transform.TransformPoint(CorrespondingCollider.center); |
|
if (Physics.Raycast(ColliderCenterPoint, -CorrespondingCollider.transform.up,out hit, CorrespondingCollider.suspensionDistance + CorrespondingCollider.radius)) |
|
{ |
|
transform.position = hit.point + (CorrespondingCollider.transform.up * CorrespondingCollider.radius); |
|
} |
|
else |
|
{ |
|
transform.position = ColliderCenterPoint - (CorrespondingCollider.transform.up * CorrespondingCollider.suspensionDistance); |
|
} |
|
if (itsTank) |
|
{ |
|
CorrespondingCollider.steerAngle = 0; |
|
} |
|
transform.rotation = CorrespondingCollider.transform.rotation * Quaternion.Euler(RotationValue, CorrespondingCollider.steerAngle, 0); |
|
RotationValue += CorrespondingCollider.rpm * (360 / 60) * Time.deltaTime; |
|
WheelHit CorrespondingGroundHit; |
|
CorrespondingCollider.GetGroundHit(out CorrespondingGroundHit); |
|
|
|
} |
|
|
|
}
|
|
|