Making Custom compass (Solved)

Started by MHK on

Topic category: Help with modding (Java Edition)

Last seen on 17:02, 16. Sep 2024
Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Making Custom compass (Solved)
Sun, 09/15/2024 - 07:39 (edited)

i know there's a lot of topic for making custom compass but none of them solves this problem. I think i found the solution but i don't speak math.

https://www.spigotmc.org/threads/find-angle-between-players-direction-and-a-location.134655/

double angle = (Math.atan2(l1.getX() - l2.getX(), l1.getZ() - l2.getZ()));
angle = (-(angle / Math.PI) * 360.0d) / 2.0d + 180.0d;

how can i make this in mcreator?

Edited by MHK on Sun, 09/15/2024 - 07:39
Last seen on 17:58, 2. Aug 2024
Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This Should Be The 1-1…
Mon, 07/15/2024 - 04:44

This Should Be The 1-1 Equivalent. It doesn't get the Angle Relative to your look direction, just the angle based off the global coordinates.

( https://imgur.com/a/EtFDX8Q )

code

Last seen on 17:02, 16. Sep 2024
Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i want to make a custom…
Mon, 07/15/2024 - 13:03

i want to make a custom compass but like you said this just gets the angle based on my coordinates.This only works if i look at one direction. How can i make it so it adjust itself based on my look angle?

Last seen on 00:24, 13. Sep 2024
Joined Sep 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
did you end up figuring out…
Fri, 09/13/2024 - 00:25

did you end up figuring out how to do it?

Last seen on 16:04, 16. Sep 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Use itemstates. Make your…
Sat, 09/14/2024 - 17:18

Use itemstates. Make your compass, like the minecraft one which has 32 textures. Create a custom property called angle or something. Then create your states where texture 0 is active when angle = 180 and texture 16 is active when angle = 0 etc. Divide 360 by 32 to get what angle each compass state needs to be in and use a value list e.g texture 0 is active when angle >= 170 and angle <= 190. The procedure to get the angle can be found by the angle between the players coordinates and the locations coordinates which is what OsutanTerra posted. However you want it based on player direction instead of player coordinates. I dont know how to do it but you can use the raytrace x y z procedure block to find what block the player is looking at. You can then use that location(A), the players location(B) and the location the compass is pointing to(C). This makes a triangle ABC. The angle we need is angle ABC, so use the xz values to get the length of lines AB and BC and then use (1/2)*(a)*(b)*(Sin(AngleABC)) to get the angle ABC and input that as the custom property angle. 

 

Just to note I have not tried this and I just made this method up right now, no clue if it works. Ill let you know if I end up using it and it works.

Last seen on 16:04, 16. Sep 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Actually 1/2abSinC is not…
Sat, 09/14/2024 - 17:27

Actually 1/2abSinC is not the right equation for this, its a^2 = b^2 + c^2 - 2bcCosA. For the above example it would be:

a = length BC, b = length AC, c = length AB, B = angle ABC

b^2 = a^2 + c^2 - (2*a*c)*(Cos(B))

The output would be B which you would set as the angle variable.

Last seen on 17:02, 16. Sep 2024
Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I made it. google drive link…
Sat, 09/14/2024 - 20:17

I made it. google drive link of the workspace
https://drive.google.com/drive/folders/1bsK_91JMWbWUVdiYugXV3TB5JY_7BD5e?usp=drive_link
Compasses name is snail compass because 1 i copied it from my other workspace and 2 i dont know how to rename it
its not perfect but who notices that. You can remove compass right clicked on block its just for debuging.
and dont put and scoreboard on sider bar for dark purple team because for some reason mcreator cant get scoreboards if it doesnt apear on sidebar so i made it on purple team like who would notice.
If drive doesnt work tell in the comments so i would repair it.
If you dont understand my english its my bad.
 

Last seen on 16:04, 16. Sep 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The drive worked and I got…
Sun, 09/15/2024 - 03:42

The drive worked and I got the workspace and it does work pretty well. Although I dont know why you made the scoreboard as you can just use a gobal variable attached to the player, or possible an nbt tag. Im glad you figured it out and got it working.

Last seen on 17:02, 16. Sep 2024
Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I Dont know how to make a…
Sun, 09/15/2024 - 07:38

I Dont know how to make a global variable specific to every player but scoreboard worked well. 
There is only one thing missing and thats detect if player is in the nether or the end.

By the way, thank you for your comments, they were very helpful making this project.

Last seen on 16:04, 16. Sep 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
For the variable just use a…
Mon, 09/16/2024 - 15:58

For the variable just use a player persistant number variable. I did recreate the compass using that and it somewhat worked but it did become janky after about a minute and stopped working sometimes. For the nether and end, in the return property procedure just make an if dimension of entity is the end or nether = true then return 0 or whatever number on a default itemstate. You could make an animated texture like the recovery compass so the needle is swinging randomly if not in the overworld or wherever you want it to be.