Racing Game positioning system! [2.49 and 2.5]

Ever made a racing game? not known how to get the positions for each player? Well, now you can! I got bored and was prompted to help out, and this is the result. Simple an easy to implement. Simply run the script, module mode, on each car, attach a sensor to the track, and away you go! The car needs a property named “Dist”, and the lower this is, the closer they are to the finish, person with the lowest value is winning…

(You will need to make an array of the average points for the tracks, but it won’t be too difficult)

Track.blend (180 KB)

track2.blend (321 KB)

In the demo, WASD for movement, there are 2 scenes.

I get an error when I run this > Object has no attribute ‘getOwner’ (line 5).

But it sounds amazing! However, I’m a bit thick, how do you make an array that lists the average ;points in the track?

2.5 Version above!

To make an array of the average points, as I don’t know non-BGE programming, you have to note down each co-ordinate as shown in the picture. You select the pairs of vertices, one pair after the other, going across the track. Each pair will give an X, Y and Z, which you note down in a co-ordinates array, inside a bigger array. The example can be seen in the “precomputed” text file.


track2.blend (321 KB)

Amazing work! How the hell did you come up with it though? Are you some kind of cyborg?:cool:

If by cyborg you mean “really nerdy guy who relishes a logic/maths challenge”, then yes, yes I am :smiley: The worst part was the “solving” whereby you have to convert equations into variable declarations… horrible stuff imo

And to think I felt like a super genius when I got a list to work! Well, I doff my cap to you sir! The only weakness to this (still bloody cool) system is the vertex definitions, I will have to use a lower resoltion track (I’ve got loops to deal with too!) Is there a way to do this automatically, sort of a macro that checks for vertex edges (sort of like in the mesh selection tools)? That would make this system really complete.

But don’t get me wrong, I don’t want to sound ungrateful because you’ve made an epic tool that will be VERY useful to many people.



thanks :smiley:
as for the array, I have been meaning to dive into the world of non-BGE scripting (I’ll have a look now). The only issue is that it would be so easy to do using some simple maths to manipulate index values, but (in 2.49 at least) vertices are assigned seemingly “random” indices, due to the fact that each vertex exists separately in each polygon it is part of, which makes life that extra bit difficult.

I was meaning to suggest having your level, then making a low poly version of the track, perhaps a bit below it, make it invisible, and ghost, and use that for the positioning, so you don’t have to mess with your ground - especially if the topology isn’t the simple 1 face wide pattern used by the script.

I also thought about the sub mesh below the track, which is very do-able. One question- what is the difference between the sprint and track scripts?

none, except the array of average points, which will need to be different for each track. If you only wanted to use one script, you could make all the arrays in one script, but only use one, based on the current track being raced.