Solved Locations to the side of players direction

Discussion in 'Plugin Development' started by TheEnderman, Feb 13, 2017.

Thread Status:
Not open for further replies.
  1. Right, so say I have a player facing north, how would I get the direction exactly 90 degree to left and right? E.g. Player is facing positive x, it then spawns a line of particles going on z and -z (left and right) I would also like to know how to make this work on any yaw angle, say 248 degrees.

    Sorry if you didn't understand it, it is a bit hard to explain.
     
  2. Offline

    Innuendo

    90 degrees of Positive X (East) is South.

    player.getLocation().add(0, 0, 1);

    Which gives you 1 block to the right of the player.
     
  3. You missed the part about it working with any degree such as 258 or 173
     
  4. Offline

    Innuendo

    I don't know how to do that, sorry.
     
  5. Offline

    Drkmaster83

    Basic Vectors, even using the rule of the negative reciprocal for a line perpendicular. Vectors can be looked at like slopes. 90 degrees is easy, so lucky for you.
    Code:
    Vector v = p.getLocation().getDirection();
    Vector v1 = v.clone().setX(-v.getZ()).setZ(v.getX());
    Vector v2 = v.clone().setX(v.getZ()).setZ(-v.getX());
    p.getWorld().spawnParticle(Particle.BARRIER, p.getLocation().add(v1.toLocation(p.getWorld())), 1);
    p.getWorld().spawnParticle(Particle.BARRIER, p.getLocation().add(v2.toLocation(p.getWorld())), 1);
    
    This puts them to either side of me. To get them X blocks away, I imagine you v1.multiply(X) and v2.multiply(X)
     
  6. Thanks!
     
  7. Offline

    Zombie_Striker

    @TheEnderman
    If your problem has been solved, mark this thread as solved.
     
  8. Already done
     
Thread Status:
Not open for further replies.

Share This Page