Standard assets CarWayPointBased: how to let the vehicle drive and stop?

Hi guys,

I am new to Unity. When I am making use of CarWayPointBased, I set the “Driving” value to false because I don’t want the car to move at the beginning.

I noticed there is a function called SetTarget() in CarAIControl script, so I cited it with a destination point as argument.

It seems the destination and m_Driving value has set correctly. I can see the wheels rotating with smoke behind the wheel. But the car does not move.

Additionally, if I set initial “Driving” value to true, the car does move. Problem is I want to stop it and restart it as I want.

Can anyone tell me what problem is it? I couldn’t find any tutorials or user guide for this library…

There’s one more way to do this
you make a new program of only calling functions of car.
for eg - your program name is call.cs
in which you have boolean values

move;

so in the car control program you may use

if(move==true)

//car should move//speed=100

else

//car stops//speed=0

i.e. you should control the cars speed…

i hope you have got your answer…

Im gonna answer this because I ren into the same issue. SidDixit solution will work. however, the car’s speed is read only and changing speed directly is not a smooth realistic stop.

another way is to set m_Driving = false;

looking at the FixedUpdate() in the AICarControll, it looks like this (i think…i did change the script a bit)

 if (m_Target == null || !m_Driving)
        {
            // Car should not be moving,
            // use handbrake to stop
            m_CarController.Move(0, 0, 0f, 1f);
        }
        else
        {

so, setting m_Driving = false is identical to using the brakes (fourth argument: handbrake = 1) in the user controlled prefab car.
if you do this, the car will stop. but, making it drive again is trickier than simply setting m_Driving to true again.
why?

If you played a little with the CarUserControl.cs (the other car prefab thats controlled by the input axis),
you’ve notice that if you make a full stop (using the spacebar or what ever your jump axis is) and than press the foward key (up arrow or w), the car wont go! its stuck! why? no clue…i personally consider it a bug.
the way to make the car go again is a tiny (even just one frame) negative acceleration (down arrow or s keys). and only then press the forward key.

we can do the same with the AICarControl. this is how I did it:

 private void FixedUpdate()
    {

        if (m_Target == null || !m_Driving)
        {
            // Car should not be moving,
            // use handbrake to stop
            m_CarController.Move(0, 0, 0f, 1f);
        }
        else
        {
             ......
             ...... 
             ......
            if (m_CarController.CurrentSpeed < 0.002)
            {
                accel = -0.1f;
            }

            m_CarController.Move(steer, accel, accel, 0f);
            ......
             .......
            .......

and the actual stop and go functions are simply setting m_Driving:

 void ReleaseBrakes()
    {
          m_Driving = true;
    }

    void HitBrakes()
    {
           m_Driving = false;
    }