Solved Getting offset position(dependent on direction)

Discussion in 'Plugin Development' started by microgeek, Jun 2, 2013.

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

    microgeek

    Hey, I need to get a location that is(solely for example) 10 blocks to the right of a player. I've tried getting the player's direction(n, s, e, w)and manually adding an offset. This worked when the player was facing perfectly in one direction, but as expected did nothing when the player was angled. I just can't wrap my head around the math required to get the needed location. Any input is appreciated.
     
  2. Offline

    Ewe Loon

    ok, first I will assume you are no worries about up and down

    you need the angle the player is facing and their position,
    float yaw=Player.getLocation().getYaw();
    float xp=Player.getLocation().getX();
    float zp=Player.getLocation().getZ();

    then use some trigonometry to calculate the position of the block you want

    int nx=xp+sin(yaw)*rht+cos(yaw)*fwd;
    int nx=zp+cos(yaw)*rht-sin(yaw)*fwd;

    all going well nx and nz will be the position of the block rht meters right and fwd meters forward from the player
    if it not right try changing the +'s and -'s around
    you may also have to convert yaw from degrees to radiens or from radiens to degrees (I cant remember which are used in MC and java)
     
    microgeek likes this.
  3. Offline

    microgeek

    I knew I shouldn't have slept thought half of my math classes. Thanks man.
     
Thread Status:
Not open for further replies.

Share This Page