Solved Vectors: Add one block in direction

Discussion in 'Plugin Development' started by Pink__Slime, May 25, 2013.

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

    Pink__Slime

    Hey,
    How would I go about getting one block in front of a player? I currently have player.getLocation().getDirection() but it returns a vector and I can't figure out how to add one block to the direction they are facing.
    E.g.
    Player is facing North, so it will take off 1 on the z.
     
  2. Offline

    caseif

    Why not just get the yaw, find which direction the player is facing from it, and place block accordingly by adding to or subtracting from the value of the x- or z-axis?
     
  3. Offline

    Pink__Slime

    AngryNerd
    Could do that... I'll try it out and come back.

    AngryNerd
    Ok... Could you possibly post some code showing how I'd do that? Can't figure it out.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  4. Offline

    Pink__Slime

  5. Offline

    blablubbabc

    Does player.getLocation().add(player.getLocation().getDirection()).getBlock(); work ?
     
  6. Offline

    Pink__Slime

    blablubbabc
    For what I want to use it for, no. Basically, (I think I should've mentioned this in OP), I want to launch a projectile that looks like it's coming from the players head.
    The only way I can do it without it hitting the player is player.getEyeLocation().add(0, 1, 0); which I don't want because then it's near impossible to aim the projectile perfectly.
     
  7. Offline

    blablubbabc

    You can set the projectiles shooter so it doesn't hit him. Also you can use what i have posted above but with player.getEyelocation and you can multiply the direction vector with any double to scale it.
     
  8. Offline

    Pink__Slime

    blablubbabc
    Code:java
    1. WitherSkull wither = p.getWorld().spawn(p.getLocation().add(p.getEyeLocation().getDirection().getBlock()), WitherSkull.class);

    The method getBlock() is undefined for the type Vector.
     
  9. Offline

    blablubbabc

    i am sorry i am writing via phone:

    WhitherSkull skull = ...spawn (p.geteyelocation ());
    Skull.setShooter (p);
    Skull.setvelocity (p.getlocation ().getdirection ());

    Or dont you want to set the shooter ?

    Then you could:

    ...spawn (p.geteyelication ().add (p.getlocation ().getDirection ().normalize ()));
     
    Pink__Slime likes this.
  10. Offline

    LucasEmanuel

Thread Status:
Not open for further replies.

Share This Page