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
0
Question by NiteshRathi05 · Nov 25, 2017 at 01:58 PM · car gamecar physics

How to make a startline and finishline? I'm making a car game. Help me.!!

I have a simple carController script. I want to display some UI text like ready steady go! and when go text is display and gone. Player car and AI car can run. And when cars reached the finishline car automatically stopped running. How to do it.

//CarController1.js var wheels : Transform[];

var enginePower=150.0;

var power=0.0; var brake=0.0; var steer=0.0;

var maxSteer=25.0;

function Start(){ rigidbody.centerOfMass=Vector3(0,-0.5,0.3); }

function Update () { power=Input.GetAxis("Vertical") enginePower Time.deltaTime 250.0; steer=Input.GetAxis("Horizontal") maxSteer; brake=Input.GetKey("space") ? rigidbody.mass * 0.1: 0.0;

 GetCollider(0).steerAngle=steer;
 GetCollider(1).steerAngle=steer;
   
 if(brake > 0.0){
     GetCollider(0).brakeTorque=brake;
     GetCollider(1).brakeTorque=brake;
     GetCollider(2).brakeTorque=brake;
     GetCollider(3).brakeTorque=brake;
     GetCollider(2).motorTorque=0.0;
     GetCollider(3).motorTorque=0.0;
 } else {
     GetCollider(0).brakeTorque=0;
     GetCollider(1).brakeTorque=0;
     GetCollider(2).brakeTorque=0;
     GetCollider(3).brakeTorque=0;
     GetCollider(2).motorTorque=power;
     GetCollider(3).motorTorque=power;
 }

}

function GetCollider(n : int) : WheelCollider{ return wheels[n].gameObject.GetComponent(WheelCollider); }

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by shakecaine · Nov 25, 2017 at 02:40 PM

Create two empty gameobjects representing start and finish. Add colliders to them like for example BoxCollider and make them triggers. Use OnCollisionEnter to detect collision with your car and execute functions to handle the rest of what is supposed to happen. Here you have reference to the script manual: https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html?_ga=2.5525685.747375645.1511525148-435282229.1502711943

Comment
Add comment · Show 2 · 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 NiteshRathi05 · Nov 26, 2017 at 07:04 PM 0
Share

@shakecaine Thanks for replying me. Your answer is O$$anonymous$$! But I add some "ui text" to the scene and have the text:Ready s$$anonymous$$dy Go! And I want that when the UI text is over, when my race starts. how to do it?

avatar image shakecaine NiteshRathi05 · Nov 26, 2017 at 11:21 PM 0
Share

If you want "Ready, S$$anonymous$$dy, Go!" then i propose you to use Coroutines. As you could do Ready and wait 1/2 second, S$$anonymous$$dy and so on and after just unlock controls for the car. In the coroutine you just change text of the UI.

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

72 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Better RPM?? 0 Answers

Problem with cars in Unity 5 0 Answers

How add kilometre per hour system in car script,how to add kilometre per hour speed system in script 0 Answers

Car Physics 0 Answers

2D Car problem with motor 0 Answers


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