• News

• Industries

• Learning & Support

• Community

• Marketplace

# Calculating Player position based on another Actor?

Hey all, I’m developing a “racing” game where there will be hundreds of players. It’s not a traditional racing game in the sense that there is a linear track. There will not be a track, rather, there will be a location that everyone is racing toward. I would like to be able to create a scoreboard that shows player positions (1st, 2nd, 3rd place, etc.) in relationship to the object that they are moving toward. In the video below you can see all of my blue/white balls are attracted to the sphere.

How would I go about recording which player (ball) is closest to the giant sphere? I can think of the basic idea but have no clue how to get started in Blueprints. I’m assuming it’s something along the lines of; Get world location of giant sphere. Get the world location of each player. Subtract the world location of the players to the giant sphere and whatever players world location value is closest to 0,0,0 is in first? Would I need to set up a timer on a tick to calculate every frame? How would I take this information and then translate it into a scoreboard?

What would your method be for doing this? Thanks!

Get Distance To node returns a float. You could loop through every player/actor of class distance to goal and fill your scoreboard accordingly.

Yes (tick). Just just have 1 blueprint with reference to all players, sort them and update scoreboard in one function. That should be enough.

1 Like

What pezzott1 say, here just quick example in Level Blueprint (i use variables of my project, but you will have the idea):

1 Like

Exactly. To this you need to add the logic for sorting distances and keeping track of their names in order (perhaps consider one float and one string array), preferably before filling the “distance array” and after the cast. On for each loop completed, update the scoreboard.

Also consider playing with the tick interval, have it update 0.33 or so. Enough so players can’t tell it’s lagging a couple of frames.

Thanks @Fortirus and @pezzott1 . I’ve copied your code a bit and then I broke out 4 of my balls into different nodes just to see what was happening. I’m struggling to find documentation on how to take this information and filter it to determine who is closest to the center? I’m assuming that I need to create a data table and sort by lowest number or something? Then convert that to a scoreboard using a widget?

This might help. That I know of, there is nothing that will help you sort an array, so you need to create that yourself.

In my humble opinion, from your blueprints I can see you are looking at the problem the wrong way. All you need is a loop that goes through all your actors, logic to add them in order to an array and finally push that to your widget.

Do you know how to use loops? Have to ask, it’s something you need to understand if you want to solve this.