# car movement basics

 0 [Solved]1. I got a car that I've made and a script I found that I've tweaked a little, but the problem is that the car isnt doing what I want it to.It is fairly easy to handle at low speeds but if it goes a little faster than that it flips as soon as I turn a little to one side.I read somewhere about changing gravity might fix it but I dunno how.also, the turning speed is like same as the torque which isnt what I want, fast turning and maby not as fast for moving.(should be changeable)2.Now the car turns right when I try to go forward in a straight line and left when I go backwards,code: ``````if(speed > maxSpeed){ RearLeftWheel.motorTorque = 0; RearRightWheel.motorTorque = 0; }else{ if(speed != 0) throttle = Input.GetAxis("Vertical"); else throttle = Input.GetAxis("Vertical") - 0.3; FrontLeftWheel.motorTorque = EngineTorque * throttle; FrontRightWheel.motorTorque = EngineTorque * throttle; //I tried fixing with this but didnt help FrontLeftWheel.motorTorque = FrontRightWheel.motorTorque; FrontRightWheel.motorTorque = FrontLeftWheel.motorTorque; } FrontLeftWheel.steerAngle = 20 * Input.GetAxis("Horizontal"); FrontRightWheel.steerAngle = 20 * Input.GetAxis("Horizontal"); ``````EDIT: Use This Demo to see how the car behaves if it helps(Tip, use F to see each wheels rpm)I find the turning most noticable at low speeds too. more ▼ asked Jun 17 '12 at 10:18 PM multinfs 21 ● 7 ● 12 ● 13 Bump...... Jun 27 '12 at 03:23 PM multinfs add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 Yes, the wheels need to be "pointed" in the correct direction. If the car is spinning, left wheels are not going the same direction as the right wheels. I wouldnt bother with trying to rotate the geometry wheels until all of the physics are correct.It's easy to have way too much torque, balancing the mass and tork is important to get realistic effects.The trick listed above to lower the center of gravity is very important, otherwise your center of gravity is the geometric center of your collider. A real car is very dense at the botom....Also, when you drive at a high speed in real life, the centrifugal force of the wheels makes it tough to steer and adds stability (like a bicycle). In my driving game, I make steering less effective at high speeds, this decreases the car flipping. more ▼ answered Jun 25 '12 at 07:37 PM crogers 31 ● 1 ● 4 I have fixed the turning at low speeds already and no need to fix at high speeds cause the car is going fast enough. But the problem is that the throttle gets stuck at over about 60km/h.` Input.GetAxis("Vertical");` Jun 28 '12 at 12:21 PM multinfs add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Not sure if it will help, but the front wheels on real cars are turned very slightly inward at the front. This is called "toe in" and is the reason why your steering wheel straightens out when you're moving forward and let the wheel turn on its own. That might help with the steering drift problem you're having. I couldn't get the car to flip when I turned at up to 60mph - but I did some sweet skids. Honestly the best five minutes of my day so far. more ▼ answered Jun 27 '12 at 03:49 PM Chuck 1 21 ● 1 ● 3 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 You may have too much EngineRPM and EngineTorque also if you have a rigidbody you should set the mass to 1500 that is a normal cars mass. more ▼ answered Jun 23 '12 at 01:45 PM Chris12345 276 ● 2 ● 19 ● 40 also make sure that your centre of mass is a empty game object and is placed in the centre of the car. Jun 23 '12 at 01:47 PM Chris12345 Ah, I fixed the flipping just with making a new clean script without the gear thingy. But now I have a new problem, the car like turns when I put some throttle on. I checked each tires rpm and it looks like the right sides wheels are turning faster when I start from stand still. Same with when I go backwards.its weird cuz they are both controlled by this: ``````FrontLeftWheel.motorTorque = EngineTorque * throttle; FrontRightWheel.motorTorque = EngineTorque * throttle; `````` Jun 24 '12 at 02:01 PM multinfs You will need to make sure your wheels all line up perfectly too, double check each colliders properties also. Jun 24 '12 at 09:48 PM pudd1nG I checked and double checked, all lined up and same settings. I just cant believe how it can behave like this. Theres nothing that interfears with them exept that the wheels are "inside" of the car, which havent caused any trouble yet. Jun 24 '12 at 10:03 PM multinfs I also found out that the rear wheels get some sort of random rotation that make them turn a little, have tried a few ways but so far havent found a way to keep them still... Jun 24 '12 at 11:43 PM multinfs add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Put this on your car and place script in a java script. and add a rigged body to you car setup and you are done. hope this works for you. `````` var rearWheel1 : WheelCollider; var rearWheel2 : WheelCollider; var frontWheel1 : WheelCollider; var frontWheel2 : WheelCollider; var wheelFL : Transform; var wheelFR : Transform; var wheelML : Transform; var wheelMR : Transform; var wheelRL : Transform; var wheelRR : Transform; var steer_max = 20; var motor_max = 40; var brake_max = 100; var steerSpeed = 20; private var steer = 0; private var forward = 0; private var back = 0; private var brakeRelease = false; private var motor = 0; private var brake = 0; private var reverse = false; private var speed = 0; function Start() { rigidbody.centerOfMass = Vector3(0, -0.05, 0); } function FixedUpdate () { speed = rigidbody.velocity.sqrMagnitude; steer = Input.GetAxis("Horizontal"); forward = Mathf.Clamp(Input.GetAxis("Vertical"), 0, 1); back = -1 * Mathf.Clamp(Input.GetAxis("Vertical"), -1, 0); if(speed == 0 && forward == 0 && back == 0) { brakeRelease = true; } if(speed == 0 && brakeRelease) { if(back > 0) { reverse = true; } if(forward > 0) { reverse = false; } } if(reverse) { motor = -1 * back; brake = forward; } else { motor = forward; brake = back; } if (brake > 0 ) { brakeRelease = false; }; rearWheel1.motorTorque = motor_max * motor; rearWheel2.motorTorque = motor_max * motor; rearWheel1.brakeTorque = brake_max * brake; rearWheel2.brakeTorque = brake_max * brake; if ( steer == 0 && frontWheel1.steerAngle != 0) { if (Mathf.Abs(frontWheel1.steerAngle) <= (steerSpeed * Time.deltaTime)) { frontWheel1.steerAngle = 0; } else if (frontWheel1.steerAngle > 0) { frontWheel1.steerAngle = frontWheel1.steerAngle - (steerSpeed * Time.deltaTime); } else { frontWheel1.steerAngle = frontWheel1.steerAngle + (steerSpeed * Time.deltaTime); } } else { frontWheel1.steerAngle = frontWheel1.steerAngle + (steer * steerSpeed * Time.deltaTime); if (frontWheel1.steerAngle > steer_max) { frontWheel1.steerAngle = steer_max; } if (frontWheel1.steerAngle < -1 * steer_max) { frontWheel1.steerAngle = -1 * steer_max; } } frontWheel2.steerAngle = frontWheel1.steerAngle; wheelFL.localEulerAngles.y = frontWheel1.steerAngle; wheelFR.localEulerAngles.y = frontWheel2.steerAngle; wheelFR.Rotate(0, 0, frontWheel1.rpm * -6 * Time.deltaTime); wheelFL.Rotate(0, 0, frontWheel2.rpm * -6 * Time.deltaTime); wheelMR.Rotate(0, 0, rearWheel1.rpm * -6 * Time.deltaTime); wheelML.Rotate(0, 0, rearWheel2.rpm * -6 * Time.deltaTime); wheelRR.Rotate(0, 0, rearWheel1.rpm * -6 * Time.deltaTime); wheelRL.Rotate(0, 0, rearWheel2.rpm * -6 * Time.deltaTime); } `````` more ▼ answered Jun 25 '12 at 02:31 PM Chris12345 276 ● 2 ● 19 ● 40 Well thanks for your answer but I'd like to stay with the code I have and the wheels should turn around the x axis cuz they are weirdly turned and I have no idea how to fix that, I have tried with changins steerangle which only turns on Y axis to transform.rotation.x but they are still turned wrong way. The code I had before used this line:transform.rotation = CorrespondingCollider.transform.rotation * Quaternion.Euler(0, CorrespondingCollider.steerAngle + 90,RotationValue); Jun 25 '12 at 06:46 PM multinfs Try changing your wheel collider rotation. the wheel operates off of the in order to work. Jun 25 '12 at 06:55 PM Chris12345 Cars can be purchased online now, gone are the days when the buyer use to visits several showrooms to purchase cars and they were very expensive, due to online selling the cost of setting up showroom is saved and hence the seller is willing to sell the car in low price. 車査定 Jun 26 '12 at 05:16 AM mikehussy Come one, you don't even bother to use english now ? Jun 26 '12 at 05:21 AM Berenger @Chris12345 I tried but the wheels themselves turns back to being horizontally instead of vertically. I'd really like to know whats wrong with my other code.EDIT: I fixed the turning at low speeds with setting all wheels motortorque to the front left wheel but it seems like the Input.getAxis("Vertical") is stuck after the car goes over about 60-80km/h(speed = FrontLeftWheel.rpm * 0.07619;) Jun 27 '12 at 01:58 PM multinfs add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x3445
x1364
x416
x52
x10

asked: Jun 17 '12 at 10:18 PM

Seen: 1903 times

Last Updated: Jun 28 '12 at 12:22 PM