Quantcast
Channel: Questions in topic: "wheelcollider"
Viewing all articles
Browse latest Browse all 490

Wheel Collider tires veer left without the required input.

$
0
0
I am writing a simple wheel-collider based car controller for my game. However, When I tested it, the car started veering towards the left even when I didn't give it any directional input. On further inspection, I came to realize that the force exerted by the front left tire of my car was a bit more than other 3 tires. The other 3 exert the same force as calculated by Wheelhit.force but the front left tire, for some reason exerts exactly 20 N more force. I have posted the image. Lforce denotes the force exerted by the front left tire. Rforce, BLforce and BRforce are front right, back left and back right respectively. My alignments and tire positioning is symmetrical so odd positioning should not be an issue. Here is the code that I have written. using System.Collections; using System.Collections.Generic; using UnityEngine; public class simpleCarController : MonoBehaviour { public WheelSystem wheels; public float maxMotorTorque; public float maxSteeringAngle; public float stoppingPower; private bool brake = false; public void Update() { if (Input.GetKeyDown(KeyCode.Space)) { brake = true; } if(Input.GetKeyUp(KeyCode.Space)) { brake = false; } } public void FixedUpdate() { float motor = maxMotorTorque * Input.GetAxis("Vertical"); float steering = maxSteeringAngle * Input.GetAxis("Horizontal"); wheels.frontRight.motorTorque = motor; wheels.frontLeft.motorTorque = motor; wheels.frontRight.steerAngle = steering; wheels.frontLeft.steerAngle = steering; brakes(wheels); } private void brakes(WheelSystem wheels) { if (brake) { wheels.frontLeft.brakeTorque = stoppingPower; wheels.frontRight.brakeTorque = stoppingPower; wheels.backLeft.brakeTorque = stoppingPower; wheels.backRight.brakeTorque = stoppingPower; } if(!brake) { wheels.frontLeft.brakeTorque = 0; wheels.frontRight.brakeTorque = 0; wheels.backLeft.brakeTorque = 0; wheels.backRight.brakeTorque = 0; } } } [System.Serializable] public struct WheelSystem { public WheelCollider frontLeft; public WheelCollider frontRight; public WheelCollider backLeft; public WheelCollider backRight; } I have omitted the debug stuff. Any assistance would be greatly appreciated. I looked up a bunch of posts on this forum from people who had a similar problem but none were able to provide a solution that worked for me. ![alt text][1] [1]: /storage/temp/198627-tirenormal.png

Viewing all articles
Browse latest Browse all 490

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>