0

This is about how to track the player. Normally, you can enable player tracking by setting a spawn point in the compass, but I want it to be displayed in the actionbar. You put a tag "main" on the player you want to display and a tag "target" on the player you want to track. Then, I want to use arrows "↑↓→←" from the player with the tag "main" in the direction of the player with the tag "target" who is somewhere in the east, west, south, north, south and west. More specifically, I would like to include northeast, southeast, southwest, and northwest in addition to east, west, south, and northwest. How can I do this?

What I have done so far: I was able to rotate by 22.5 degrees in y_rotation, up to creating 8 ranges, I just don't think this is the right thing to do: (

ver 1.19.4

I solved it, so I will write the solution. hope it helps someone!

Thanks to @Samstercraft and @Plagiatus, I was able to figure out what to do :) My y_rotation was not wasted either. lol

Here is how I did it:

After calculating the difference between each coordinate, I executed commands separately for each number using a function. Since there were two test numbers for x and y, and three numbers (-1, 0, 1) to display, I created 8 files using 2³.

execute if score @s pos.x matches 0 if score @s pos.z matches 1.. run ...

(pos.x and pos.y are calculated by subtracting "main" tags from "target" tags.)

Then, within each file, I detected 8 directions using y_rotation and was able to display the appropriate direction.

For example: execute if entity @s[y_rotation=-22.5..22.5] run title @s title "↑"

I was able to create the command I wanted. It was a very informative learning experience. Thank you so much! :)

1
  • Math and scoreboards. Lots of scoreboards. I dont have time rn so im just leaving a comment, but here's something to get started with this method: /data store result data get (or something like that) can retrive player coords and put them in a scoreboard, bossbar, or a few other locations. (i think coords are stored in Pos[0] Pos[1] Pos[2] but not sure if thats in a subtag, u can mess around with data command and check out nbt path format.) You can see if a score is greater or less than a value with a target selector placed somewhere, maybe in execute command idk rn, eg. @a[score=1..] is 1+ May 12, 2023 at 10:43

1 Answer 1

1

As @Samstercraft so eloquently put it in their comment: "Math and scoreboards. Lots of scoreboards".

Since scoreboards are just integer variables and they come with a full set of basic arithmetic operations, I'm just going to link to further info about the scoreboard command, while only going into the math part here.
So, see https://minecraft.wiki/w/Commands/scoreboard for how to use the scoreboard command, as well as https://minecraft.wiki/w/Commands/execute#if for execute if score which might come in handy, too.

First, one more before the math: we gotta get both players position into respective scores. For that you can use the following command. Pos[0] is the X position, use 1 and 2 respectively for the y and z position. Though the Y position seems to be irrelevant for the problem.

execute as <player> store result score @s xPos run data get entity @s Pos[0]

Now, the math.

What we want to figure out is whether the difference between the two positions is mainly in one direction or roughly in two directions. So first we calculate the difference by doing TargetPosition - MainPosition. This should give us the difference between the two, specifically where the Main needs to change position to get to the Target. (e.g. if Main is at 100, 100 and Target is at 130, 90 then the difference is 30, -10)

We could stop here and display that in the main players actionbar by writing out the 4 combinations (+/- X/Z) and displaying the appropriate one (probably also changing depending on their current rotation instead of up arrow always meaning north, so another 4 mutations so 16 title commands), but since you said you'd want a diagonal one, instead of two arrows or just the biggest one, we need to do an extra step:
Check if the two differences are roughly the same amount, and if they are, display a diagonal arrow instead. There are many ways to do this and they get complicated fast, especially with limited operators. But the easiest way is probably to just calculate the difference between distanceX and distanceY, see if the difference is below a threshold, say 10 blocks, and then display the arrow diagonally if they are.

3
  • 1
    getting quoted has made me very happy lol May 13, 2023 at 6:54
  • 1
    Thank you both. Completed without incident! :)
    – wood
    May 13, 2023 at 10:29
  • @wood ayyyy lets goo glad i could help :) May 14, 2023 at 5:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .