Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var path : Array;
- var pathGroup : Transform;
- var maxSteer : float = 15.0;
- var wheelFL : WheelCollider;
- var wheelFR : WheelCollider;
- var wheelRL : WheelCollider;
- var wheelRR : WheelCollider;
- var currentPathObj : int;
- var distFromPath : float = 20;
- var maxTorque : float = 50;
- var currentSpeed : float;
- var topSpeed : float = 150;
- var decellarationSpeed : float = 10;
- function Start () {
- var path_objs : Array = pathGroup.GetComponentsInChildren(Transform);
- path = new Array();
- for (var path_obj : Transform in path_objs){
- if (path_obj != pathGroup)
- path [path.length] = path_obj;
- }
- }
- function Update () {
- Getnode();
- currentSpeed = 2*(22/7)*wheelRL.radius*wheelRL.rpm * 60 / 1000;
- currentSpeed = Mathf.Round (currentSpeed);
- if (currentSpeed <= topSpeed){
- wheelRL.motorTorque = maxTorque;
- wheelRR.motorTorque = maxTorque;
- wheelRL.brakeTorque = 0;
- wheelRR.brakeTorque = 0;
- }
- else {
- wheelRL.motorTorque = 0;
- wheelRR.motorTorque = 0;
- wheelRL.brakeTorque = decellarationSpeed;
- wheelRR.brakeTorque = decellarationSpeed;
- }
- }
- function Getnode(){
- var steerVector : Vector3 = transform.InverseTransformPoint(Vector3(path[currentPathObj].position.x,transform.position.y,path[currentPathObj].position.z));
- var newSteer : float = maxSteer * (steerVector.x / steerVector.magnitude);
- wheelFL.steerAngle = newSteer;
- wheelFR.steerAngle = newSteer;
- if (steerVector.magnitude <= distFromPath){
- currentPathObj++;
- if (currentPathObj >= path.length)
- currentPathObj = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement