Rotate mob/player

Discussion in 'Plugin Development' started by Jerry Larsson, Feb 11, 2011.

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

    Jerry Larsson

    Is there a way to rotate a mob or a player that I've spawned to the world?
    I can only see how to set X, Y, Z, Yaw and Pitch.

    Maybe there's a method in the minecraft.server package that you know of?

    Any help would be appreciated, if you have hacks or a clean solution, anything.

    Thanks.
     
  2. Offline

    fullwall

    Yaw is for horizontal rotation, pitch for vertical rotation. Use them to rotate mobs/players.
     
  3. Offline

    Jerry Larsson

    Yes. But when changing Yaw they turn their head. And I can't figure out to what value to set on yaw to make the playe rotate to a certain Direction like N, E, S, W. Any help on that would be great.
     
  4. Offline

    fullwall

    Are you using player.setYaw() or Location.setYaw()?
     
  5. Offline

    Jerry Larsson

    player.setYaw()

    Actually I'm using se.minecraft.server.EntityPlayer.

    EntityPlayer.c(x, y, z, yaw, pitch);
     
  6. Offline

    fullwall

    Try using location.setYaw(), might fix your issue.
     
  7. Offline

    Jerry Larsson

    What values does Yaw accept? Is it Radians, Degrees or what unit is it?
     
  8. Offline

    fullwall

    Degrees, pretty sure. 360 - negative 360 (I believe it's based on orientation). But in programming, it's best just to try stuff out :p.
     
  9. Offline

    Plague

    Yaw is in degrees, but watch out, because it's not just 0 to 360, but its a float and minecraft can easily return -3649.45, dunno why it's like that or if it was not only a bukkit thing at the time, just so you know.
     
  10. Offline

    fullwall

    Yeah, yaw can be funny like that :S. I tend to work with it by multiplying it by a certain number...
     
  11. Offline

    eisental

    To get the absolute angle you can do: angle = getYaw() % 360.
    I'm not sure about what values you should have for different compass directions but you can just check it by looking north and checking the yaw value (after % 360). Basically each direction (N NE E SE etc...) should have a 45 degrees range.
     
  12. Offline

    Plague

    You are forgetting negative numbers...
    Code:
    String facing[] = {"W", "NW", "N", "NE", "E", "SE", "S", "SW"};
    double yaw = ((loc.getYaw()+22.5) % 360);
    if (yaw < 0) yaw = 360 + yaw;
    player.sendMessage("Facing " + facing[(int)(yaw / 45)]);
     
Thread Status:
Not open for further replies.

Share This Page