How to get yaw, pitch and roll from a vector?

Discussion in 'Spigot Plugin Development' started by fortressworks, Apr 17, 2019 at 2:13 PM.

  1. You don't. A vector is a direction, not a position.
     
    • Agree Agree x 2
  2. And I think we only have pitch and yaw in Minecraft.
     
    #3 NascentNova, Apr 17, 2019 at 2:49 PM
    Last edited: Apr 17, 2019 at 2:59 PM
  3. I think maybe armor stands have some kind of roll property on some of the movable limbs, though I'm not entirely sure.

    Though, as others have said, a vector is an object which indicates movement. It's not a location. The X, Y and Z value indicate where the momentum is going. The values of the vector have no relation to an actual location. They're relative values. The higher the values, the greater the force of the vector (higher momentum).
     
    #4 MrDienns, Apr 17, 2019 at 3:02 PM
    Last edited: Apr 17, 2019 at 3:10 PM
    • Informative Informative x 1
    • Agree Agree x 1
  4. Pitch and yaw are actually direction :)

    The roll does not really exist for a direction, you don't need it.
    You can simply use
    Location l = anyLocation;
    l.setDirection(yourVector);
    and
    l.getYaw();
    l.getPitch();

    If you do not want to use Location, you can still follow this cult tutorial:
    https://bukkit.org/threads/tutorial-how-to-calculate-vectors.138849/

    Finally if you want the head of an armorstand looking at a direction you can use this:

    Code (Text):
        double yaw = Math.atan2(direction.getZ(), direction.getX());
                double pitch = Math.atan2(Math.sqrt(direction.getZ() * direction.getZ() + direction.getX() * direction.getX()), direction.getY()) + Math.PI;
                projector.setHeadPose(new EulerAngle(-pitch + Math.toRadians(90), yaw + Math.toRadians(90), 0));
     

Share This Page