Answer the question
In order to leave comments, you need to log in
Why is the script not working correctly?
hello. please tell me why the script is not working correctly
using UnityEngine;
using System.Collections;
public class CarController : MonoBehaviour {
public WheelCollider[] WColForward;
public WheelCollider[] WColBack;
public float maxSteer = 30; //1
public float maxAccel = 25; //2
public float maxBrake = 50; //3
// Use this for initialization
void Start () {
}
void FixedUpdate () {
float accel = 0;
float steer = 0;
accel = Input.GetAxis("Vertical"); //4
steer = Input.GetAxis("Horizontal"); //4
CarMove(accel,steer); //5
}
private void CarMove(float accel,float steer){ //5
foreach(WheelCollider col in WColForward){ //6
col.steerAngle = steer*maxSteer; //6
}
if(accel == 0){ //7
foreach(WheelCollider col in WColBack){ //7
col.brakeTorque = maxBrake; //7
}
}else{ //8
foreach(WheelCollider col in WColBack){ //8
col.brakeTorque = 0; //8
col.motorTorque = accel*maxAccel; //8
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question