Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by realhly88 · Dec 14, 2015 at 10:01 AM · vehiclestandard assets

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...

Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image realhly88 · Dec 14, 2015 at 04:55 PM 0
Share

Anybody knows?

avatar image jmonasterio realhly88 · Dec 14, 2015 at 05:34 PM 0
Share

It's easier to answer your question if you paste in the code that you've written, ins$$anonymous$$d of trying to describe it in words.

avatar image realhly88 jmonasterio · Dec 14, 2015 at 05:55 PM 0
Share
 using System;
 using UnityEngine;
 using Random = UnityEngine.Random;
 using UnityStandardAssets.Utility;
 
 namespace UnityStandardAssets.Vehicles.Car
 {
     [RequireComponent(typeof(CarController))]
     [RequireComponent(typeof(CarAIControl))]
     public class StopForLoading : $$anonymous$$onoBehaviour
     {
         public Transform testTarget;
         private CarAIControl referencedController;
         private WaypointProgressTracker referencedWaypointTracker;
 
 
         private void Start()
         {
             referencedController = gameObject.GetComponent<CarAIControl>();
             referencedWaypointTracker= gameObject.GetComponent<WaypointProgressTracker>();
             StopTheCar();
             Invoke("StartTheCar", 10);
         }
 
         private void StopTheCar()
         {
             referencedController.stopDriving();
         }
 
         private void StartTheCar()
         {
             referencedController.SetTarget(referencedWaypointTracker.target);
             Debug.Log(referencedWaypointTracker.target.name);
         }
 
 
 
     }
 }

What I am doing in the code is stop the car first, then in 10 seconds, start the car and let it move to the first point in the WayPointCircuit.

What stopDriving does is simply assign m_Driving in CarAIControl to false.

SetTarget is a function exists in CarAIControl.

Show more comments
avatar image Tanoshimi2000 · Dec 17, 2015 at 07:23 PM 1
Share

I am having the exact same behavior. If I call SetTarget() in the Awake() function, the car takes off normally, but if I leave the Target as null, or mark m_Driving = false, and then call SetTarget() later (after my race countdown), the car stays in place and spins tires. It's like a parking brake is set, but I don't see anything like that.

$$anonymous$$eeping an eye on this thread for an answer/workaround. If I come up with one, will post solution.

avatar image Jervbear · Sep 08, 2017 at 04:37 PM 0
Share

Has anyone found the solution for this yet?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by SidDixit · Dec 19, 2015 at 08:08 AM

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....

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by DanielleSisserman · Aug 12, 2018 at 10:38 AM

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;
     }


Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tgd-uni · May 23, 2019 at 12:07 PM 0
Share

@$$anonymous$$leSisserman Thank you posting! Was having a hard time finding out whats wrong with the start stop behaviour. Thanks for the "fix".

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Vehicle automatically accelerates with any input on Logitech G29 1 Answer

Standard Assets Car Automatically Accelerates and Turns Left 0 Answers

Standard Asset Car won't shift past 3rd gear yet coding is set to 5 gears. 1 Answer

car AI to slow down in turns 0 Answers

how can i make a player get in a vehicle? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges