Get direction to Entity

Recommended Posts

How would I go about getting the direction an entity is based upon the players current rotation yaw. Example: Say the player is looking North and the entity being tracked is behind the player, the direction would be south, and the same for all other directions. The direction would be entirely based upon where the entity is, and the players rotation yaw.

Share on other sites

Do you want the direction to be in terms of pitch and yaw? if so, do you want them relative to the player's pitch and yaw or absolute?

Either way I suggest looking up ray tracing

Share on other sites

Step 1: assume the player is at 0,0,0

Step 2: trigonometry

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

• Thank you for your answer ! Unfortunatly i have the same problem when i use setPos() public static int movingfunction(CommandContext<CommandSourceStack> context){ CommandSourceStack source = context.getSource(); if (!(source.getEntity() instanceof ServerPlayer)) { return 0; } ServerPlayer player = (ServerPlayer ) source.getEntity(); double moveSpeed = 0.5; for (int i =0; i<10000;i++) { LOGGER.info("running for the {} time", i); double x = player.getX() + player.getViewVector(1.0f).x * moveSpeed; double y = player.getY(); double z = player.getZ() + player.getViewVector(1.0f).z * moveSpeed ; Vec3 movementVec = new Vec3(x, y, z); LOGGER.info("x ={} y ={} z ={}", x, y, z); player.setPos( movementVec); } return 1; } With the logs i can see that x and z are increasing but once again my player is not moving. is there a function to use to sync the server and the client ? I also tried to use LocalPlayer instead of ServerPlayer but my code would stop when i got the object. Also i will change a bit the main topic but is there a way to similate key press ? i found KeyBinding.setKeyBindState on others post but it look like there is no more KeyBinding in 1.20
• Use Java 17
• Add crash-reports with sites like https://paste.ee/ Maybe an issue with blur, essentials or cumulus_menus
• Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here

• Who's Online (See full list)

×

• Activity

×
• Create New...