How to Track Every Player and Find Their Distance [ đŸŸ„ 8/10]

Welcome to my BIGGEST GUIDE YET!

I’ve looked far and wide into the deepest depths of the forums and haven’t found a reliable way to get every player’s position and store it, and no way to find the distance between 2 players. UNTIL NOW! I have been working on this system for a while now. Bug fixing, optimizing, and I’ve finally gotten it to work. This will work for however many players you have in your game and doesn’t require any manual input from the player (except them needing to move around ofc lol)! Let’s get to work!

What we'll be making

Untitled video (2)
The overlay in the top left shows the players’ position. The one in the bottom left shows the name, x, y, and distance of the closest player to you. (Disclaimer: this video is of the old version. The new version is a lot faster.)


Materials

This list is sorted first by the greatest number of devices to the least, then by how much memory they use.

Property ×14 (140 memory)
Trigger ×6 (3,240 memory)
Game Overlay ×2 (1,350 memory)
Relay ×2 (40 memory)
Speed Modifier ×2 (20 memory)
Player Coordinates ×1 (4,000 memory)
Lifecycle ×1 (50 memory)
Counter ×1 (25 memory)
Friends: 3 recommended, but good luck getting any :index_pointing_at_the_viewer: :joy:
Total memory: 8,865 :exploding_head:


Now that you have everything you need, let’s get to it!

System setup

To make this system, we need every player’s data to be the same length as everyone else’s to prevent bugs. But usually, every player in the game has different names that are different lengths. To make the system work properly, everyone’s name needs to be the same length. So, how do we do that? Well, the longest length that a player can set their name to is 20, so let’s make a system that does exactly that!

Let’s build it!

First, grab a lifecycle and set it up like this:
image

But if we just leave it like this, then the system will only work for the game host. So, we need to add a relay for the other players.
image

We broadcast on “Game start relay” that way if there’s ever another point where we need to make a system similar to this (when we want not only the game host to have the event happen for) then we can reuse this same lifecycle and relay for as many times as we need!

Now to make the actual system. Start by grabbing a Speed Modifier and set it up like this:
image

We need to do this that way the player can’t move before we set their name, otherwise the system will break. Setting the player’s speed to 0 will fix that.

Now, we can finally set the player’s name! Get a property with these settings:

Now let’s make a trigger loop that will set the property for us.

Heads up!

All of the triggers in this guide have these settings enabled.
image
image

Have it trigger when receiving on this broadcast:
image

For more info on what this is and how this works, read this amazing guide by Blueboat!
Breaking the recursion cap | TUTORIAL | Difficulty: :orange_square: - Community Made Guides - Gimkit Creative
Yay first link!

Now make a new code block and make it like this:
image

Congratulations, you’ve just made a trigger loop! This will set the “My name” property until it has a length of 20!

Special character

For this system, I used a special character that appears invisible on most devices. This usually includes mobile devices, and macs, but I do not yet know whether or not it appears invisible on Chromebook. I’m on windows, so for me, it looks like a little box, but since most people play Gimkit on a school laptop, this should work very well! Idk why it appears invisible in my pictures and not on my PC, but if you look at the GIF in the showcase, you should be able to see the boxes in the overlays.
Here is the character that I used. You should be able to copy-paste it into the text block in the photo that appears to be empty:

If you’re unable to do it here, then you can just look up “Invisible text” in your browser and it should take you to a link where you’ll be able to copy it by pressing a button. If everything is blocked for you, then you can go to scratch.mit.edu, go to the search bar, type in %15, and the character should be there where you’ll easily be able to copy-paste it. If that doesn’t work, womp womp lol.



Tracking every player's coords

Now that we’ve set up our name, it’s time to track every player’s coords at the same time! But once again, we want the length of the player’s data to be the same as everyone else’s. This means that the length of the players coords has to be the same as everyone else’s. The largest number our coords can be is 640 which has a length of 3, so we want our coords to have a length of 3, even if our actual coords are lower than 100.

Time to build!

Get 4 new properties called “x”, “y”, “x space”, and “y space”.

Then get the “Player Coordinates” device and make a block like this:

If the length is already 3, then we’ll go straight to save the player’s position, otherwise, we’ll use a trigger until the length is equal to 3. We use 2 separate properties that way we can use number properties for math, and text properties for spacing.

Let’s code the trigger that sets our spacing first. Have it trigger on “Fix numbers”.
image

Make a new block like this:

How it works

We combine the length of our actual coords with the length of the text to check how long it is. If it’s not equal to 3, then we’ll just add on the special character to the front of the spacing property. Then we check if both lengths are greater than or equal to 2. If it says it’s equal to 2, then that means it’s actually equal to 3 because we just updated it.


Now let’s code the other trigger. But first, add 2 new properties like this:

Now we can finally code the trigger. Make it trigger when receiving on “Update position” like this:
image

Make a new block with this code:


How it works

WOW this is a lot of code. What does this even do?
Well, what the code does is get information from a property, figure out which part of the information belongs to the player, and replace it with our new information. Basically, we’re getting the substring of the property that contains all of the player data from the start to the individual players info, then we insert our new info, and then get the substring from the end of our info to the end of every player’s info. However, if we can’t find the player’s data, then we add it on to the end of the property that contains all of the player data.


You’ve now successfully added a way to track every player’s coords. Let’s add an overlay that displays all of the players’ info. Add an overlay and make a new block:
image

image
Now the players’ names and positions should appear on the overlay!


Tracking the distance between us and other players

This was the hardest part for me to figure out. You have to somehow get numbers out of a text property? How do you do that? Allow me to show you! But first, let’s make some new properties.

Now get a counter and give it these settings:


image

And get a relay:
image

Now get a trigger. Make it trigger when receiving on “Compare coordinates”:
image

Make a new block like this:
image

Now we need to make 3 more properties:

Now get a trigger that triggers on “Text to number”:
image

Make a new block:

Make one last property called “Closest player data”:

And make one last trigger that triggers when receiving on “Function”:
image

Make a block like this:

And now, you have completely made a system that will find the closest player to you!

How it works

Ima try to keep this short bc I’m really tired of working on this lol.
The math behind setting the starting letter variable allows us to find the first letter in every 29 letters.
Special thanks to @TorontoBulls1 for showing me the system used to convert text into numbers. I have no idea how it works, but it does lol.
We use the Pythagorean theorem to find the distance between our coords and the player that we’re tracking’s coords, unless the player we’re tracking is ourselves.
We check if they’re the closest player to us, then save everything to a property for later.
Then we restart the loop.


Now, let’s code an overlay that displays all of the information about the closest player.
Make sure the overlay’s position is in a different spot from the first one. I used bottom right.
Make a new block:
image

image


Now, get some friends into your game and start it! Does everything look correct? I sure hope so!

Disclaimer

This system might break if 2 people with the same name join, or if a player joins late. I tried to fix it for when a player joins late but it didn’t work. However, you can disable late joining in your map settings:
image


Thanks for reading this guide! It took a very long time to make, but I think it was worth it!
What are some things this may be useful for? It could be used as a powerup in a battle royale to get the jump on your opponents! Or perhaps add a range to the distance, to make a honing missile using a damager, or do the same thing for a more realistic unaliving mechanic in among us games!

If you’re having any trouble building this, have any questions or found an optimization, drop a reply! :arrow_double_down:

Can’t wait to see what you guys come up with! Happy building!
–Fulcrum-19

Rate my guide?
  • AMAZING!!!
  • Good!
  • Ok.
  • Bad.
  • WORST GUIDE EVER!
0 voters
What is the difficulty? DO NOT VOTE 11 JUST FOR FUN :rage:
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
0 voters
12 Likes

Amazing guide! I love it, and it is VERY detailed! :full_moon: (And no, I didn’t vote 11 just for fun, those code blocks are deadly :skull:)

2 Likes

Great guide! An awesome addition to the community. It shows so much more effort than most of the guides i’ve seen this summer.

I wish someone would have been able to catch this before you went through the pain of making it but you can convert text to a number by storing it in a variable or storing it in a property (assuming it is actually a number e.g. a text string containing 12) and then performing a math operation on it.

Here’s an example

These will both output the string as numbers. Keep in mind you can also use a property in the same spot as the variable.

5 Likes

No way. That’s crazy. Thanks for letting me know

2 Likes

Np. It’s really useful. I wish i had known ab it earlier

2 Likes

This is very helpful! I will definitely be using it for a variety of maps. Great job!
What was the process of figuring this out?

Oh, wow! I just skimmed, but that looks hard! I love all the detail you put into in, so all in all, great guide!

2 Likes

This is too much for my brain to comprehend. It’s a good guide though!

At first, I just wanted to save every player’s coords on to 1 property, but then I thought it would be cool if I could fetch the data somehow and use it. I had a very hard time trying to optimize the block code.

2 Likes

Huh, it isn’t working in the system.

3 Likes

Try outputting the TextToNumber variable into a testing property (text) and see what it is showing. If it is the correct numbers then let me double check something

2 Likes

Ok I think I see what’s wrong with it now. It appears that I did the math wrong. Let me try to fix it.

Edit #1: I fixed the math, and the number is coming up correctly. Let me see if the distance is working yet

Edit #2: yep, it worked! I’ll be sure to update this. It’s a lot faster now.

2 Likes

I love this guide! Much needed as TorontoBulls said, no guides really doing much effort
 ig the math is mathing, and you did it in an understandable way! Thanks so much Fulcrum!

2 Likes

Great work. Glad to help. Awesome that it improved performance too.

Just updated it with the new system!

1 Like

Cant you just use waypoint (following player) with a relay that says ‘all players on game start’?

Just wondering

Yeah, but you can’t get their exact positions, or make cool mechanics out of it.

3 Likes

Amazing guide with a lot of pictures! I’ve made something like this before, but this guide’s mechanics are way smarter.

1 Like

I didnt have to read this to give it a 10/10 it just is perfect and just like unit_72 said those blocks are deadly :skull:

1 Like

Why don’t you try learning how to do block code?

3 Likes