x


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.

more ▼

asked Feb 26 '12 at 10:52 PM

Dee Va gravatar image

Dee Va
279 4 14 18

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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 !

more ▼

answered Feb 27 '12 at 12:56 AM

Berenger gravatar image

Berenger
11k 12 19 53

sorry sir, i didn't understand your answer :( actually am asking this (http://i39.tinypic.com/1fi6ph.png) please help me. thank u....

Mar 18 '12 at 11:06 AM Dee Va

Even i have the same problem :(

Jul 17 '12 at 01:53 AM Bhasker reddy

Oh, right. I was thinking minimap 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.

Jul 17 '12 at 02:01 AM Berenger

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

Jul 17 '12 at 02:54 AM Dee Va

I'm afraid it was off the top of my head. I'm assuming 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.

Jul 17 '12 at 04:31 AM Berenger
(comments are locked)
10|3000 characters needed characters left

do you mean rank detector sir?

more ▼

answered Jul 17 '12 at 03:23 AM

vanofthedawn12 gravatar image

vanofthedawn12
96 3 6 10

Exactly :D

Jul 17 '12 at 12:55 PM Dee Va
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Jul 17 '12 at 03:25 AM

vanofthedawn12 gravatar image

vanofthedawn12
96 3 6 10

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x886
x418
x14

asked: Feb 26 '12 at 10:52 PM

Seen: 1243 times

Last Updated: Jul 17 '12 at 12:55 PM