Getting location relative to player's direction

Discussion in 'Plugin Development' started by Chr0mosom3, Jan 28, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    Chr0mosom3

    How would I go around getting locations relative to player's current direction he is looking. I cannot use x and y values since they are not dependent on where the player is looking. I am trying to spawn armor stands over there.

    I am trying to spawn armor stands at the red boxes:
    upload_2021-1-28_16-41-7.png
    Using location.clone().add(xOffset, yOffset, zOffset) would work over here, but how would I do it in a situation like this:
    upload_2021-1-28_16-42-23.png
    Over here the player isn't looking at a certain direction and it would be impossible to get the coordinates using offsets.


    Another question, how would I get the block NW of the player specifically (hilighted in green):
    upload_2021-1-28_16-43-30.png
     
  2. Offline

    Kars

    You can use LivingEntity#getTargetBlock and from there figure out the direction relative to the players location.
     
  3. Offline

    Chr0mosom3

    @Kars
    What exactly is getTargetBlock? If it's the croshair position, then I don't think that's too useful, in the examples the player was looking down, but that was just so I could get the top view of the blocks, in an actual scenario the player could be looking wherever.
    How exactly would I do that?
     
  4. Offline

    Kars

    getTargetBlock returns the block where the player is looking. Blocks have a location that you can compare with the players location. That way you can deduce the general direction in which the player is looking.

    Edit:
    Probably better to use Player#getLocation#getDirection
     
    Last edited: Jan 28, 2021
  5. Offline

    Chr0mosom3

    How would I do either of those options


    Sent from my motorola one vision using Tapatalk
     
  6. Offline

    Kars

    Read the documentation for getDirection or getYaw.
     
Thread Status:
Not open for further replies.

Share This Page