# get player facing direction

## Recommended Posts

I found the following in GuiRender

int var24 = MathHelper.floor_double((double)(p.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

and this gives an direction of 0/1/2/3

I was wondering how I could make this give me diagonal facing directions as well 0/1/2/3/4/5/6/7

All I know from this is that p.rotationYaw can be bigger than one rotation of a circle (more than 360) so we get it down to between 0 and 360

but after this function completes it only gives 4 possible values

0/1/2/3

note: I am not good when it comes to floating point math

##### Share on other sites

int var24 = MathHelper.floor_double((double)(p.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

Isn't the 4.0F what is giving you 4 output numbers..  So in theory if you changed it to 36.0F it would give you 36 possible outputs, each one representing a 10 degree facing..

Therefore 8.0F would give you your diagonals I think..

0 = North

1 = North East

2 = East

3 = South East

4 = South

5 = South West

6 = West

7 = North West

(Or whatever direction starts at 0 )

##### Share on other sites

I tried changing it to 8.0F but it still returned 0/1/2/3 but they were not the right directions

##### Share on other sites

Hmmm

If you change the &3 to &7 what happens ?

##### Share on other sites

Minecraft Gui / var24 with the &7

SOUTH/NORTH

inbetween south and west/NORTHWEST

WEST/NORTHEAST

inbetween north  and west/EAST

you get the idea

##### Share on other sites

Or you can use the built in feature "look"

do you a) mean the F3 information showing the F: variable if so

this only shows SOUTH WEST NORTH EAST and does not show diagonal directions

or do you mean get player.getLook(int par1) which returns float x,y,z which in no way at all helps me.

##### Share on other sites

no use Vec3 look = player.getLookVec() then call look.xCoord and look.yCoord and look.zCoord and then combine those together for whatever you are doing and you have the exact pixel that the player is looking at

##### Share on other sites

So basically you want something like?

int yaw = (int)ePlayer.rotationYaw;

if (yaw<0)              //due to the yaw running a -360 to positive 360

yaw+=360;    //not sure why it's that way

yaw+=22;    //centers coordinates you may want to drop this line

yaw%=360;  //and this one if you want a strict interpretation of the zones

int facing = yaw/45;  //  360degrees divided by 45 == 8 zones

System.out.println("Yaw is " + yaw + "facing is " + facing);

*note this was validated with 1.45 code base your mileage may vary

##### Share on other sites

So basically you want something like?

int yaw = (int)ePlayer.rotationYaw;

if (yaw<0)              //due to the yaw running a -360 to positive 360

yaw+=360;    //not sure why it's that way

yaw+=22;    //centers coordinates you may want to drop this line

yaw%=360;  //and this one if you want a strict interpretation of the zones

int facing = yaw/45;  //  360degrees divided by 45 == 8 zones

System.out.println("Yaw is " + yaw + "facing is " + facing);

*note this was validated with 1.45 code base your mileage may vary

Thanks this worked absolutely perfectly.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• ### Posts

• Hello, I am experiencing the following error once an hour and sometimes two hours, does anyone know what might cause the crash? Is it a mod that is causing it or is there a mod that can fix that? Server Forge version: 1.20.1 Forge: net.minecraftforge:47.2.20   JVM Flags: 24 total; -Xms128M -Xmx16384M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1NewSizePercent=40 -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=15 Mods: - fightorflight-forge-0.5.3.jar - BadMobs-1.20.1-19.0.2.jar - netherportalfix-forge-1.20-13.0.1.jar - NoChatReports-FORGE-1.20.1-v2.2.2.jar - architectury-9.1.13-forge.jar - accelerated-decay-forge-3.0.1+mc1.20.1.jar - ferritecore-6.0.1-forge.jar - balm-forge-1.20.1-7.2.1.jar - Terralith_1.20.4_v2.4.11.jar - memoryleakfix-forge-1.17+-1.1.5.jar - cloth-config-forge-11.1.106.jar - kffmod-4.10.0.jar - Cobblemon-forge-1.4.1+1.20.1.jar Error: https://pastebin.com/XKNM1Ak5 Stacktrace: https://pastebin.com/GESmmB4s
• Merging Minecraft modpacks is simpler than it sounds. Just think of it as combining ingredients from two recipes into one. If you're not sure how to start, there's a handy tutorial on YouTube titled "How to combine mods in Curseforge Minecraft" that breaks it down step by step. It's like following a cooking show but for Minecraft mods. And if you need more help, the Reddit's r/feedthebeast are like the community kitchen where everyone shares their cooking tips.
• String Name: 1 wanderlite_matrix Class Name: class net.minecraft.world.item.ItemStack Mod Name: Clockwork: Create x Valkyrien Skies Registry Name: vs_clockwork:wanderlite_matrix Display Name: Wanderlite Matrix Yes
• Tried panorama_screens and some other mod, but it still gives me the same error : https://pastebin.com/CG2hUbcY What is the problem exactly ? Is there a problem with the model of one of the items of Clockwork ?
• Been having this crash report on a pack I'm running with some friends. No idea what's causing it, was able to replicate this crash by making a new modpack with nothing but mekanism in it https://pastebin.com/RNQLVEP4 Mekanism definitely isn't the problem I've just identified it as having items that create this rendering error below is a further crash report, same error just not mekanism  https://pastebin.com/D05EQW5U Any help would be greatly appreciated

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...