- Home /
position indicator for car in racing game ?
how to make the position indicator for racing games,which shows the current position of the player(car)....
anyone please.
Answer by Berenger · Feb 27, 2012 at 12:56 AM
It depends how you're displaying the minimap (that's what you're talking about right ?). I will assume it's a GUI. Here is what I would do :
Set an empty gameobject at the 3D position (let's call it A) which represent your minimap's top left corner. The y doesn't matter. It's likely to be the corner of your terrain. Set another gameobject for the bottom right (B).
Find the position of the car in A's space, with transform.InverseTransformPoint. Then, Divide it by the magnitude of the vector [AB]. IF it's not a square, divide separetely x and y. Now you have the car's position in your GUI relative rect's space, between 0 and 1.
Finally, multiply that by that rect's size.
I have no idea if it works !
sorry sir, i didn't understand your answer :( actually am asking this (http://i39.tinypic.com/1fi6ph.png) please help me. thank u....
Oh, right. I was thinking $$anonymous$$imap apparently. The easiest way (ok, the only one) I see right now, is to have waypoints all along the race path, sorted from start to end. Each frame, each car search the closest waypoint.
Best case scenario, all the cars have a different waypoint, they are already sorted. But you can have several cars with the same point, in which case you need to calculate how close they are from the next one. I can develop that part if need be.
Even I didn't solved this problem,@Berenger Any Reference script's about this please because I have no idea how to do that, thank you :D
I'm afraid it was off the top of my head. I'm assu$$anonymous$$g you already have several cars running against each other, either multiplayer or AI, create a basic race with a single straight line, with at least 2 vehicles (let's call them A and B).
Create the start at (0,0,0), end at (0,0, 100). Then create 5 empty GO, set them at z == 0, 25, 50, 75 and 100. In your vehicle script, create a public transform array var, and assign those 5 GO, by increasing z order.
At runtime, inside the HUD script (which is attached to only one object, by opposition with the vehicle script I spoke earlier), loop through all the vehicles to find the index of their closest point. If A is at z == 47.89 and B is at 86.41, A's index is 2 and B's is 3. 3 > 2, B is first. Note that this could be done by comparing the z of each vehicle. But this case is very specific, and the path in a race turns and turns, that's why you need waypoints.
I suggest you do that first, then try to think about the worst case scenario, for instance A 47.89 and B 53.66, which gives the same index for both.
Answer by vanofthedawn12 · Jul 17, 2012 at 03:25 AM
maybe we could use trigger detection.. if a car pass through another's trigger the passing objects would rank up high and the object that has been passed lose one position.. nah not quite sure just a thought..
Answer by kapyar · Feb 09, 2016 at 05:14 PM
Hey, you could try my plugin which can handle all math. Its really simple to use you must add only 2 prefabs to your scene https://www.assetstore.unity3d.com/en/#!/content/45698
Your answer
Follow this Question
Related Questions
How to make a Race Standing / Position Indicator 0 Answers
problem wheel position 1 Answer
Making a race car positioning system 5 Answers
Camera rotation around player while following. 6 Answers
Car's position indicator or Standings . 2 Answers