I’ve been trying to figure out how to calculate race position (IE 1st, 2nd, 3rd etc.) for my game but it’s really stumping me.
I figured an easy way to do this would be to place a spline in my game that follows the track, and then get each player’s percentage along that spline and set this as a Race Progress float variable.
My code for that is here: Get Percentage Along Spline posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4
This works perfectly, each racer (hoverbike) has its own unique float value based on where they are along the spline. I thought the next part would be easy too; get all of the racers in the world, then compare the RaceProgress variables and sort them into order 1 through 8 as there are 8 players total.
My code for this is here:
I can’t figure out why this isn’t working. The racers seem to be getting a random number assigned to them, even though I’m going through the vehicles one at a time and assigning them a rank starting at 1 based on the highest value in the array. As you can see here, the person in first place is listed as 3 then there’s two 0s and a 6 followed by the last in the group being 4th. It doesn’t make any sense to me.
I should say that I’m checking the RacePosition on a timer set to trigger every 0.333 seconds but of course, I only open the gate once the first check has completed to prevent the arrays from being adjusted during the calculation.
If anyone can point out what I’m doing wrong it would be greatly appreciated.