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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by toto92 · May 02, 2014 at 07:06 AM · positionairacingranking

ranking in race Game

This is my IA Script about my Car but i need to add the rank or position of my car in race how to do it:

var CenterDeGravite :Vector3;

 var Chemin :Array ;
 var CheminGroupe :Transform;
 var MaxAngle :float =15.0;
 
 var RavG :WheelCollider;
 var RavD :WheelCollider;
 var RarG :WheelCollider;
 var RarD :WheelCollider;
 
 var Chemin_obj_Actuelle :int;
 var Distanc_Depuis_Chemin :float=20;
 
 var MaxMoteur :float =50;
 var VitesseActuelle :float;
 var TopVitesse :float=150;
 var DecellerationVitesse :float =10;
 var ArriereLightD : GameObject;
 var ArriereLightG : GameObject;
 var FreinMain : boolean =false;
 var frienmech : Material ;
 var danssecteur : boolean ;
 var longueurcapteur : float = 5;
 var avantcapteurdebut : float = 5 ;
 var avantcapteurdistance : float = 5;
 var avantcapteurangle : float = 30 ;
 var laterlacapteurlongeur : float = 5 ;
 private var flag : int = 0 ;
 var eviter_sensibilite : float = 0 ;
 
 
 function Start () {
 rigidbody.centerOfMass = CenterDeGravite; 
 GetChemin();
 
 }
 
 function GetChemin(){
 
 var Chemin_objs :Array = CheminGroupe.GetComponentsInChildren(Transform); 
 
 Chemin = new Array();
 
 for(var Chemin_obj : Transform in Chemin_objs){
     if(Chemin_obj != CheminGroupe)
     Chemin [Chemin.length]= Chemin_obj;    
 }
 
 
 }
 
 function Update () {
 
 
 MarcheArriereLight ();
 GetAngle();
 Mouvement();
 capter();
 
 }
 
 
 function GetAngle(){
 
 var AngleVector :Vector3 =transform.InverseTransformPoint(Vector3(Chemin[Chemin_obj_Actuelle].position.x,transform.position.y,Chemin[Chemin_obj_Actuelle].position.z));
 var NouveauAngle :float = MaxAngle *(AngleVector.x / AngleVector.magnitude);
 RavG.steerAngle =NouveauAngle;
 RavD.steerAngle =NouveauAngle;
 
 
 if(AngleVector.magnitude <= Distanc_Depuis_Chemin) {
     Chemin_obj_Actuelle++;
     if( Chemin_obj_Actuelle >= Chemin.length){
         Chemin_obj_Actuelle=0;
     }
 }
 }
 
 
 function Mouvement(){
 VitesseActuelle = 2*(22/7)* RarG.radius * RarG.rpm *60 /1000 ;
 VitesseActuelle = Mathf.Round(VitesseActuelle);
 
 if(VitesseActuelle <= TopVitesse && !danssecteur) {
     RarG.motorTorque= MaxMoteur;
     RarD.motorTorque= MaxMoteur;
     RarG.brakeTorque=0;
     RarD.brakeTorque=0;
 }
 
 else if (!danssecteur) {
     RarG.motorTorque=0;
     RarD.motorTorque=0;
     RarG.brakeTorque=DecellerationVitesse;
     RarD.brakeTorque=DecellerationVitesse;
 }
 
 
 } 
 
 function MarcheArriereLight () {
   
     
     
 
  if (VitesseActuelle <0  && FreinMain ){
     ArriereLightG.GetComponent(Light).enabled = true ;
     ArriereLightD.GetComponent(Light).enabled = true ;
     ArriereLightD.light.color = Color.red;
     ArriereLightG.light.color = Color.red;
     }
     
     else if (VitesseActuelle <0 &&  !FreinMain ) {
     ArriereLightG.GetComponent(Light).enabled = true ;
     ArriereLightD.GetComponent(Light).enabled = true ;
     ArriereLightD.light.color = Color.white;
     ArriereLightG.light.color = Color.white;
     }
 
     else if ( !FreinMain )    {
     ArriereLightG.GetComponent(Light).enabled = false ;
     ArriereLightD.GetComponent(Light).enabled = false;
     }
 
 
 }  
 
 
 function capter() {
 flag=0;
 var pos : Vector3 ;
 var hit : RaycastHit ;
 
 var angledroit = Quaternion.AngleAxis(avantcapteurangle,transform.up)*transform.forward;
 var anglegauche = Quaternion.AngleAxis(-avantcapteurangle,transform.up)*transform.forward;
 // avant milieu capteur
 pos = transform.position ;
 pos += transform.forward*avantcapteurdebut;
 if (Physics.Raycast(pos,transform.forward,hit,longueurcapteur)){
 
 Debug.DrawLine(pos,hit.point,Color.yellow);
 
 
 }
 // avant capteur droit
 pos += transform.right*avantcapteurdistance;
 if (Physics.Raycast(pos,transform.forward,hit,longueurcapteur)){
 if (hit.transform.tag != "terrain"){
 eviter_sensibilite -=0.5 ;
 Debug.Log("lool");
 flag++;
 Debug.DrawLine(pos,hit.point,Color.yellow);
 }
 
 }
 
 // anvant capteur angle droit
 
 if (Physics.Raycast(pos,angledroit ,hit,longueurcapteur)){
 if (hit.transform.tag != "terrain"){
 Debug.DrawLine(pos,hit.point,Color.yellow);
 
  transform.Rotate(Vector3.up,- 90 * 2* Time.smoothDeltaTime);
 
 
 }}
 
 
 
 //avant capteur gauche
 pos = transform.position ;
 pos += transform.forward*avantcapteurdebut;
 pos -= transform.right*avantcapteurdistance;
 if (Physics.Raycast(pos,transform.forward,hit,longueurcapteur)){
 if (hit.transform.tag != "terrain"){
 eviter_sensibilite +=0.5 ;
 Debug.Log("lool");
 flag++;
 Debug.DrawLine(pos,hit.point,Color.yellow);
 }
 }
 
 //avant capteur angle gauche
 
 if (Physics.Raycast(pos,anglegauche,hit,longueurcapteur)){
 if (hit.transform.tag != "terrain"){
 Debug.DrawLine(pos,hit.point,Color.yellow);
 
  transform.Rotate(Vector3.up, 90 * 2* Time.smoothDeltaTime);
 
 
 }
 
 
 }
 
 //droit lateral capteur 
 
 if (Physics.Raycast(transform.position ,transform.right,hit,laterlacapteurlongeur)){
 
 Debug.DrawLine(transform.position,hit.point,Color.yellow);
 
 
 } 
 
 // gauche lateral capteur 
 if (Physics.Raycast(transform.position ,-transform.right,hit,laterlacapteurlongeur)){
 
 Debug.DrawLine(transform.position,hit.point,Color.yellow);
 
 
 } 
 
 if (flag !=0) 
 {eviter_angle (eviter_sensibilite);}
 }
 
 function eviter_angle(sensibilite : float) 
 {
 RavG.steerAngle =MaxAngle*sensibilite;
 RavD.steerAngle =MaxAngle*sensibilite;
 
 }
Comment
Add comment · Show 1
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 darthtelle · May 02, 2014 at 07:13 AM 0
Share

That's a lot of code to go through and very little description about what you'd like help with. Could you cut it down to what is relevant and maybe explain your issue further?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · May 02, 2014 at 07:29 AM

As mentioned in the comment, that is way to much code to look at, so I won't read it and just give you some ideas on how we made it in one of our car game.

Each car starts with a value of 0 for points.

You have waypoints, which I reckon is CheminGroupe in your script. When a car passes the waypoint, points gets increased.

Ordering the cars by points then gives a first ranking.

But cars in between the same waypoint will show with same ranking or a random ranking more likely. This is where you take the distance to the next waypoint.

So first rank by points and then if some have the same amount of points rank by distance.

I would suggest to create a method that does all that then call the method via

  InvokeRepeating("CarOrder",0.5f,0.5f);

Then it won't happen each frame and half a second is enough to get accurate ranking.

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 PointyPigheadGames · Oct 19, 2016 at 09:58 PM

I'm not going to give the exact code so i'll tell you what you need to do.

In this order:

  • Are the other cars on the same lap that you are?

  • If so, are the other cars on the same checkpoint/waypoint as you are?

  • If so, are the other cars a greater distance from the checkpoint/waypoint than you are?

Next, you make an int variable that will be a 0 if the car is ahead of you, and a 1 if the car is in front of you. Finally, make another int that is 1+ car1Position + car2Position. This will be the place you're in.

This should help make an accurate ranking in a race, as long as there are enough checkpoints/waypoints.

Hope this helps! -Pointy Pighead Games

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

22 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

Related Questions

Operator `+' cannot be applied to operands of type `UnityEngine.Vector3' and `int' 1 Answer

NavMeshAgent places transform incorrectly 1 Answer

AI car Script problem 1 Answer

How can make rank in racing game? 1 Answer

How to have realistic collisions with AI in a racing game? 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