Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Luky12321 · Oct 03, 2013 at 08:18 PM · speedcar

Speed ​​car at the start of the game

I have a script.

 /*
 Script Created by FlatTutorials for "Car Controller kit".
 */
 
 @script AddComponentMenu ("FlatTutorials/Scripts/Car Control Script")
 #pragma strict
 var centerOfMass : Vector3;    //Center of mass
 var dataWheel : WheelCollider;    //Wheel Collider from which you want to calculate the speed
 var lowestSteerAtSpeed : float = 50;    //if lowestSteerAtSpeed < currentSpeed the steer Angle = highSpeedSteerAngel
 var lowSpeedSteerAngel : float = 10;    //This could be a high value
 var highSpeedSteerAngel : float = 1;    //This shouldn't be a high value (recomended for stability of car)
 var decellarationSpeed : float = 30;    //How fast the car will decellarate
 var maxTorque : float  = 50;    //Maximum Torque
 var currentSpeed : float;        //Current Speed of car
 var topSpeed : float = 150;        //Highest speed at which the car can go
 var maxReverseSpeed : float = 50;     //Highest Reverse speed
 var backLightObject : GameObject;    //Mesh for reverse light
 var idleLightMaterial : Material;    //for idle state
 var brakeLightMaterial : Material;     //Braked state
 var reverseLightMaterial : Material;    //Reverse state
 @HideInInspector    
 var braked : boolean = false;    //Brake trigger
 var maxBrakeTorque : float = 100;     //Braking speed
 var speedOMeterDial : Texture2D;    //GUI Texture for dial
 var speedOMeterPointer : Texture2D;        //GUI Texture for needle
 var gearRatio : int[];        //Shift gear at speed
 
 
 function Start () {
 rigidbody.centerOfMass=centerOfMass; //Center of mass , for this the car should be pointing on z axis
 }
 
 function FixedUpdate () {
 HandBrake();
 }
 function Update(){
 BackLight ();
 EngineSound();
 CalculateSpeed();
 }
 
 //Speed Calculation
 
 function CalculateSpeed(){
 currentSpeed = 2*22/7*dataWheel.radius*dataWheel.rpm*60/1000;
 currentSpeed = Mathf.Round(currentSpeed);
 }
 
 //Light Control
 
 function BackLight (){
 if (currentSpeed > 0 && Input.GetAxis("Vertical")<0&&!braked){
 backLightObject.renderer.material = brakeLightMaterial;
 }
 else if (currentSpeed < 0 && Input.GetAxis("Vertical")>0&&!braked){
 backLightObject.renderer.material = brakeLightMaterial;
 }
 else if (currentSpeed < 0 && Input.GetAxis("Vertical")<0&&!braked){
 backLightObject.renderer.material = reverseLightMaterial;
 }
 else if (!braked){
 backLightObject.renderer.material = idleLightMaterial;
 }
 }
 
 //Brake Trigger
 
 function HandBrake(){
 if (Input.GetButton("Jump")){
 braked = true;
 }
 else{
 braked = false;
 }
 }
 
 //Engine Sound
 
 function EngineSound(){
 for (var i = 0; i < gearRatio.length; i++){
 if(gearRatio[i]> currentSpeed){
 break;
 }
 }
 var gearMinValue : float = 0.00;
 var gearMaxValue : float = 0.00;
 if (i == 0){
 gearMinValue = 0;
 }
 else {
 gearMinValue = gearRatio[i-1];
 }
 gearMaxValue = gearRatio[i];
 var enginePitch : float = ((currentSpeed - gearMinValue)/(gearMaxValue - gearMinValue))+1;
 audio.pitch = enginePitch;
 }
 
 //Speedometer
 
 function OnGUI (){
 GUI.DrawTexture(Rect(Screen.width - 300,Screen.height - 150,300,150),speedOMeterDial);
 var speedFactor : float = currentSpeed / topSpeed;
 var rotationAngle : float;
 if (currentSpeed >= 0){
   rotationAngle = Mathf.Lerp(0,180,speedFactor);
   }
   else {
   rotationAngle = Mathf.Lerp(0,180,-speedFactor);
   }
 GUIUtility.RotateAroundPivot(rotationAngle,Vector2(Screen.width - 150 ,Screen.height));
 GUI.DrawTexture(Rect(Screen.width - 300,Screen.height - 150,300,300),speedOMeterPointer);
 
 }
 



How to make a car when you turn on the game itself went forward? Start game = auto speed 100. How to do it?

Comment
Add comment · Show 7
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 Mill0698 · Oct 03, 2013 at 09:25 PM 0
Share

Could you try and explain your question a little more in detail?

avatar image robertbu · Oct 03, 2013 at 09:27 PM 0
Share

You've got the tail wagging the dog here. This script "shows" indicators...set the speedometer, turns on/off break lights, makes engine sounds. Nothing in this script is responsible for changing the speed of the vehicle. Your change will be in some other script.

Since this is not your script, this is likely copyrighted by someone else. Are you sure it is okay to post the author's scripts here?

avatar image Luky12321 · Oct 03, 2013 at 09:30 PM 0
Share

I need to start the game when the car went forward. Sorry for my English. How do I make the car to run forward when I run the game. Start game = Car speed 100. When you turn on the game, the car had speed 100.

avatar image robertbu · Oct 03, 2013 at 09:36 PM 0
Share

@Lucky12321 - As I mentioned, this is not the script you would make that change in.

avatar image YoungDeveloper · Oct 03, 2013 at 10:20 PM 1
Share

Who publishes these kind of "questions" ? First of all this isn't question, this is "do work for me, even if i don't or can't understand anything". Plus, the user clearly have no idea or what so ever what "bla bla" is written there.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Sisso · Oct 03, 2013 at 09:40 PM

So you want to create a racing game? If so, this is my answer:

http://u3d.as/content/unity-technologies/car-tutorial/1qU

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

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

17 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

Related Questions

Car speedometer MPH 1 Answer

How to make Characters take Damage on speed Collision hit? 2 Answers

How to add car speed to a car controller script 1 Answer

How do I limit the speed of my car? 0 Answers

Car Steering Relative to Car Speed 2 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