1.8.8 Rotate Entity Vector

Discussion in 'Spigot Plugin Development' started by NemN07, Jul 5, 2021.

  1. Hi I'm trying to spawn an entity to the right of the player.
    I had already done the same thing for what spawn behind the player.

    Code (Java):
    Vector playerLookDirection = p.getLocation().getDirection();
    double X = p.getLocation().getX() + playerLookDirection.getX() * -1.5;
    double Y = p.getLocation().getY() + 2;
    double Z = p.getLocation().getZ() + playerLookDirection.getZ() * -1.5;

    How can I make it spawn on the right?
     
  2. Your code for spawning behind the player should only work in specific cases, not in general.
    can be formally described as a rotation by -90°.
    Ignore the y coordinate for a minute and focus on the xz-plane as this is the plane where we want to do the rotation.
    What you need is a rotation matrix. Solving the matrix multiplaction and considering that sin(-90)=-1 and cos(-90)=0 we can simply the math/code to
    Code (Java):
    xToTheRight = playerLookDirection.z
    zToTheRight = -playerLookDirection.x
    (Let me know if you need a more thorough explanation because I shortened the actual math a lot because a lot cuts out nicely)