- Home /
How to stop a car from veering in a particular direction?
I am using wheel colliders for my car model.I have also attached a script to make the car move.The car moves forward when I press the up arrow key but the car also slightly turns towards the left.I tried adding more torque to one of the wheels to make it move in a straight line but that makes the car behave weirdly.Need help!!!
I found this code in the unity forum to help solve this problem but the code is in C#.This code should be added to my script but my script is written in JavaScript.Can someone convert this into javascript?(I dont know C#). void Awake() { // _currentRotation is defined elsewhere in the class _currentRotation = new Vector3 (transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z); } void LateUpdate() { // whenever the car is intended to be going straight we adjust localEulerAngle; if the user steers we do not interfere but adjust the rotation angle to allow for correct further calculation // _steer is defined elsewhere and // is taken from the user in FixedUpdate() // as follows: _steer = Input.GetAxis("Horizontal"); if (_steer == 0) { float y = _currentRotation.y; transform.localEulerAngles = new Vector3 (transform.localEulerAngles.x, y, transform.localEulerAngles.z); } else _currentRotation.y = transform.localEulerAngles.y; }