hey i was following the unreal engine time attack racer series on youtube, but i am wondering how can i create a leaderboard/ racing positions table not sure what the actual term for it is but something similar to the image above what it has in the top right - i know in the game (NFS Most Wanted 2005) that it has split times as well as distance but i dont really care about that more so i just want a table that will keep track of players positions based on where they are in correlation to the final checkpoint but im not quite sure how to do it. any help is much appreciated
Hey, you could:
- Create a spline on your track with points along the race track. Then for each car get the nearest point + completed laps to calculate the positions. (for tracks without different paths)
- Create points on the track without a spline, like place down target points or something similar. This way you could include shortcuts. Then calculate the nearest point again for every car and sort them.
hi, so i’ve got the racetrack already done with splines and have checkpoints set up along the racetrack but not sure how to do the nearest point thing as im not sure how it works - if i set it up for the final checkpoint if the race has multiple laps would it not say the player in last is actually first due to them being closer to that final checkpoint?
If you set the lap for each player the last one would have Lap 0 and TargetCheckpoint 0, whereas the first player would have Lap 1 and TargetCheckpoint 6 for example. If you already have your checkpoints, then you could add points to your player when he passes one of them. Also the passed checkpoint would tell the player which checkpoint is next, so your start is Checkpoint0 tells the player the next one is Checkpoint1. With this information you could also calculate how far away the player is from the checkpoint and make this distance negative points. Cechkpoint passed=1000 points, distance to next Checkpoint= distance*-1 points. Then sort the players by points.
is it not possible for me to make it simpler and compare the players current checkpoint integer value to the integer value of the final checkpoint and order it somehow that way? thats my current idea but i have no idea how to visualise it into blueprint im not sure what nodes i would need to use etc.
The problem that would occur with just checking the checkpoint number would be that when 2 players are between Checkpoint_1 and Checkpoint_2 they would have the same position. That’s why you should somehow combine the checkpoint number and the distance to get the difference of two players while they are between the same checkpoints (or even more players).
Let’s say you have your track and divide it into segments (red lines). These segments are a blueprint of type actor with a box collision.
Whenever you pass this “wall” on the track it executes a OnComponentBeginOverlap event.
With the Checkpoint_Target you could get the location of this checkpoint from an array and then calculate the distance to it.
thanks for the help - i see what your doing but how would that translate into positions on a widget? and how would you determine whose first cos from what you’ve done there unless im missing it i dont see how first position would be determined im seeing how 2 people in the same position would be differed though. again thanks for your help
With your Checkpoints_Passed you would have a number of how much Checkpoints each player has passed. With this number you could sort the players (rough). The distance would be to fine tune the positions. So you would have these values in your PlayerState (every player counts his points). Then in your GameState you can get the PlayerArray and extract those numbers. Then you would sort them by their score (in GameState) and then get the sorted Scorelist in your Widget by using a reference to your GameState and getting those numbers (with the name or playertag or…).
so i have the checkpoint actor blueprint
and then a tracker blueprint
it works for each pawn but im not using player state or game state - the default character is a third person character who can then enter a vehicle and drive so i cant simply cast to the vehicle blueprint as you did and im just using the default player state so unsure how to do it
Is this a single- or multiplayer game? Because if it is multiplayer you should use these blueprints. If it is singleplayer, you can store these variables nearly anywhere.
multiplayer - the checkpoint system i have in the screenshots works for each player but just not sure if it would work for the racing positions
so im trying to replicate what you have now but im a little confused - so your overlap event is in the blueprint actor for the checkpoint right? you are casting to the default pawn class where you have added variables for checkpoint target and checkpoints passed - is checkpoint target the total number of checkpoints for example you have 5 segments acting as checkpoints if there is 2 laps are you changing the <= to 10 as opposed to 5?
and i believe the event tick is being done within the default pawn class blueprint also as you are getting the mesh and its location - so how would these values then be in the player state and how can i extract them into the game state? that bits confusing me and the other parts above just double checking to see if i could change the values for laps thanks for the help
CechkpointTarget= Checkpoint to aim for. When you start it is set to 0, you overlap Cechkpoint0, it gets set to 1 and so on. And it should be <5 and not <=5 for this example. Because when your CheckpointTarget is 4 it should be incremented, but when it is already 5 then it should be reset to 0. When you have all these points/variables in your pawn, you can get PlayerState in your PawnBlueprint and cast to your PlayerStateBlueprint(create one). Then you can set variables which you have in your pawn in your PlayerState also. The variables in the PlayerState have to be replicated. So you set your variables in the PlayerState from your pawn and now this PlayerState is accessable with GetGameState => GetPlayerArray. From this PlayerArray you can get all the PlayerStates (Points/Checkpoints/Distance whatever you put in it). This is useful to create a widget, because you as a client can not access the other players without it. I will try to create a short example, usually I would show you all of it but currently I am working on the same thing for a marketplace template
no problem i appreciate your help a lot - i was wondering if possible to get on a discord call or something similar where i could share screen and show what im trying to do? i know it might be asking much but i feel that would be a lot easier than screenshotting as the whole blueprint would be visible then ? its okay if not