hi,
am learning the movement of vehicles using wheel colliders. i wrote a small script to move a car and when i apply brake to it the car stops and doesn’t accelerate anymore. need help on how to once again accelerate.
using UnityEngine;
using System.Collections;
public class new_car : MonoBehaviour {
public float maxTorque = 50.0f;
public float minTorque = 50.0f;
//public float maxSteer;
public WheelCollider[] wheelColliders = new WheelCollider[4];
public Transform[] wheels = new Transform[4];
public Transform centerOfMass;
private Rigidbody n_rigidBody;
//bool brakeApplied = false;
// Use this for initialization
void Start ()
{
n_rigidBody = GetComponent<Rigidbody>();
n_rigidBody.centerOfMass = centerOfMass.localPosition;
}
// Update is called once per frame
void Update ()
{
UpdateMeshes ();
}
void FixedUpdate()
{
float steer = Input.GetAxis ("Horizontal");
float accelerate = Input.GetAxis ("Vertical");
float maxSteer = steer * 30.0f;
wheelColliders [0].steerAngle = maxSteer;
wheelColliders [1].steerAngle = maxSteer;
if (Input.GetKeyDown (KeyCode.UpArrow) || Input.GetKeyDown (KeyCode.DownArrow))
{
for(int i = 0; i < 4; i++)
{
wheelColliders_.motorTorque = accelerate * maxTorque;_
-
}*
-
}*
-
if(Input.GetKeyDown(KeyCode.Space))*
-
{*
-
for(int i = 0; i < 4; i++)*
-
{*
_ wheelColliders*.brakeTorque = minTorque;_
_ }_
_ }*_
* }*
* void UpdateMeshes()*
* {*
* for(int i = 0; i < 4; i++)*
* {*
* Quaternion quat;*
* Vector3 pos;*
_ wheelColliders*.GetWorldPose(out pos,out quat);*_
_ wheels*.position = pos;
wheels.rotation = quat;
}
}
}*_