Hello everyone! Novice here, trying to learn game dev by creating my dream game. At it’s core, it’s going to be a racing game and I have started from the vehicle template. I have added a pickup spawning system, checkpoint/laps counter and a dynamic AI racer spawner. Even a modular turret for the player car.
My question: I am trying to calculate the players placement in the race. The blueprint sequence I’ve made thus far is working..ish. But further along the race track something breaks. I can be at first place and then suddenly at last place.
Attaching a screenshot of the sequence in question. The blueprint (should) checks the players position on a race track spline relative to each AIs position on that same spline. For each AI car in the AI car array that is in front of the player one value is added to the placement counter. So for an example is only one player is in front of the player, the placement is 2nd. It works at first as I said. But then maybe at some point the sequence starts tracking a different part of the spline, because it is close or whatever? I don’t know. This is where I need your expertise!
I also tried using my checkpoint system. Checking checkpoints passed amount first, and only checking distance along spline if the amount is the same or less. Which in my mind should bypass that problem. That did not work well either. This is not implemented in my screenshot but there is an unconnected remnant. These nodes where then connected into two more branches, so three in total instead if just one here. First if AI checkpoints > player checkpoints, then AI checkpoints equal player checkpoints, then lastly if AI along spline > Player long spline.
TLDR. Looking at my BP here, what am I doing wrong OR is there a better way to create a placement tracker all together? Any help is appreciated!! Thanks!
First of all do you reset Position Counter everytime you run your test (do you set it to 0 before your for loop?)
Secondly, is your race track looped? If so, when you pass the first lap your “distance along spline” will start over, so it will be really small, while your oponents which did not finish the lap will have it much longer. You’ll have to take account of the finished laps.
Also a tip: instead of For loop you can use “For Each Loop” which automatically loops trough all of the Array entries.
Hi! Thanks for your answer! Yes, I set the position counter to 1 at the tick event start.
Yes the thought is that there will be several laps although for this particular problem you highlight here I have no fix for at the moment. I’ve set it at only 1 lap because of this. The issue comes before the first finish line passing.
So the sequence here looks all right then? Should I show more of it or some other BP it uses perhaps?
ok, so I guess the problem is you’re looking for the closest Input Key, but the scarcer the points the less accurate it is.
Isn’t there a function that returns the closest location instead of an input key?
Thanks again! This was great, 1 node where 2 was before. It did not help the issue though so I’ve been up all night troubleshooting. The issue was the loop point of the spline was not where the cars start (the start/finish line). So, I made a blueprinting offsetting the indexes of the spline to match my track setup.
It works now! Almost.. Now it says I’m starting at position 12 even though I’m at pole position, until I pass the starting line for the first time. This made me think of the intial problem you thought about @lordlolek. So, I added some nodes adding value to laps. FYI the lap doesnt count up before all checkpoints has been passed, so it shouldnt matter at the start. But it somehow does?
Here is also a screenshot illustrating my issue at the start. The player car is the one in front with the turret. It says position 12 until the starting line is passed. Again, that doesnt change the laps completed variable.
EDIT: Aah I think I have a theory. 12 of 16 cars probably end up at the end of the track instead of at the start…Some sort of individual offset of the track for the ones ending up behind the loop point? Or offsetting the track less so that all cars end up on the same side of the spline start. This got hella complicated..