x


Very Simple Car Questions

So in the game I'm making, you essentially have to drive a little truck to the pickup station, get the item that needs the delivery, then take it to the destination. I'm working on just the first level which is a straight run with no obstacles so I'm purely working on the car physics right now. I've got a simple car going, but it flips so incredibly easy it's pathetic and the car is hardly moving at all. The car is never supposed to catch any air so is there any way to constrain it to the ground? It's going to be top down so the Y-axis isn't even a factor in the game.

I lightened it up so it's more visible what's actually going on. Here's the Mac and PC stand alones, not sure how to put it as a playable game online...

Mac: http://dl.dropbox.com/u/55162513/level1mac.zip

PC: http://dl.dropbox.com/u/55162513/level1windows.zip

more ▼

asked Dec 31 '11 at 10:39 AM

kewlhead gravatar image

kewlhead
16 6 8 8

You answered yourself... "constraints" ... On your rigidbody options, contraints, freeze the Y position so it cant ever move up or down.

Dec 31 '11 at 10:57 AM Lo0NuhtiK
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

I haven't made a car in unity yet, but from what I read in the docs you should use Brake Torque for braking. Something like this maybe->

var brakeButton : String = "MyInputBrakeButtonName" ; 
var brakePower : float = 100.0 ;
 
//in update() with your other stuff->
   if(Input.GetButton(brakeButton)){
      FLWheel.brakeTorque = brakePower ;
      FRWheel.brakeTorque = brakePower ;
   }

Note: you're only going to have front brakes like that lol

more ▼

answered Jan 01 '12 at 03:59 AM

Lo0NuhtiK gravatar image

Lo0NuhtiK
3.5k 1 9 39

(comments are locked)
10|3000 characters needed characters left

That never even crossed my mind... Thanks:) Will that solve the rolling do you think?

more ▼

answered Dec 31 '11 at 11:27 AM

kewlhead gravatar image

kewlhead
16 6 8 8

You can play around with the constraint freezers and see if you can get it set up how you want it. It can freeze positions and/or rotations.

Dec 31 '11 at 11:30 AM Lo0NuhtiK
(comments are locked)
10|3000 characters needed characters left

One last question, now that I've got that all sorted out, thank you:), I'm not sure how to make a brake system. Simply pressing reverse takes forever to slow it down. I figure I have to alter the velocity in some way but have no idea how...

Here's my code:

var FLWheel : WheelCollider;
var FRWheel : WheelCollider;
var maxForwardSpeed : float= 50.0;
var maxReverseSpeed : float= 50.0;
var turnRadius : float= 30.0;
var EngineTorque : float = 25;


function Start () {
rigidbody.centerOfMass += Vector3(0, -.5, 0);
}

function Update () {


    /*Apply forward motion (Torque) to the front wheels*/
    FLWheel.motorTorque = -EngineTorque * 10 * Input.GetAxis("Vertical");
    FRWheel.motorTorque = -EngineTorque * 10 * Input.GetAxis("Vertical");

    /*This limits the car to a max speed. It is negative because the input for up and down
    are reversed for whatever reason*/

    if(FLWheel.motorTorque && FRWheel.motorTorque < maxForwardSpeed){

    FLWheel.motorTorque = -maxForwardSpeed;
    FRWheel.motorTorque = -maxForwardSpeed;

    }

    /*This limits the car to a max speed when travelling in reverse. Horizontal input is correct,
    so no negatives need to be put in place.*/
    if(FLWheel.motorTorque && FRWheel.motorTorque > maxReverseSpeed){

    FLWheel.motorTorque = maxReverseSpeed;
    FRWheel.motorTorque = maxReverseSpeed;

    }

/*Turn Radius variable increases or decreases the tightness of the turn*/
FLWheel.steerAngle = turnRadius * Input.GetAxis("Horizontal");
FRWheel.steerAngle = turnRadius * Input.GetAxis("Horizontal");

rigidbody.constraints = RigidbodyConstraints.FreezeRotationX;
rigidbody.constraints = RigidbodyConstraints.FreezePositionY;

}

more ▼

answered Jan 01 '12 at 12:31 AM

kewlhead gravatar image

kewlhead
16 6 8 8

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1963
x101
x12
x2

asked: Dec 31 '11 at 10:39 AM

Seen: 1258 times

Last Updated: Jan 01 '12 at 04:08 AM