Been Trying To Figure This Out For Weeks (Direction issues)

Discussion in 'Plugin Development' started by Taien, Jul 26, 2012.

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

    Taien

    Ok, so I have a plugin in my server that I developed which is used for protection of areas called 'estates' (it's similar to the old Residence plugin). I created a command some weeks ago to expand the estates and pay money for the difference in size. On the previous map it worked fine, but now we've generated a new map and the direction recognition is all messed up.

    So my question is this:

    How does bukkit/minecraft determine which direction a player is facing? I thought it was the Yaw, and I set up the code as follows:
    Code:
    else if (args[2].equalsIgnoreCase("forward"))
                        {
                            float direction = p.getLocation().getYaw();
                            if (direction > -45 || direction < -315) dir = LookDirection.POSZ;
                            if (direction <= -45 && direction > -135) dir = LookDirection.NEGX;
                            if (direction <= -135 && direction > -225) dir = LookDirection.NEGZ;
                            else dir = LookDirection.POSX;
                        }
    But it seems that in the new map the yaws aren't the same as they were in the previous map. So I'm guessing each map has a different rotation relative to Yaw. So how do I determine which direction a player is facing in terms of POSX, NEGX, POSZ, or NEGZ? (Btw, LookDirection is an enum I made.) I've tried looking at the Location.getVector(), but I don't understand vectors at ALL. They only have three coords and yet somehow contain a direction? Someone want to explain that to me? :/ I also noticed that if you F3 in minecraft there is a fourth coord which represents the direction called "f", but I have no idea how to access this in code.

    I could really use any help anyone can offer. I've been stumped by this for weeks and I'm tired of trying to figure out how bukkit handles look directions without any help or tutorials on the subject. Thanks in advance. Sorry for my tone of frustration.
     
  2. Offline

    nisovin

    I believe you need to do something like this to normalize the value:

    direction = direction % 360;
    if (direction < 0) direction += 360;

    A vector is just an arrow pointing in a certain direction. If the x and z values are both positive, then you can see which is bigger to determine if they're facing in positive x or positive z. And so on.
     
  3. Offline

    Taien

    Wait wait, so a Vector is essentially not a set of coordinates, but a set of differences in the X, Y, and Z coords? (lightbulbs go on) WOW. Thanks.
    And yeah, I hadn't thought to modulus the yaw. But I think the Vector thing will be much more helpful. Thanks a googleplex, dude.
     
Thread Status:
Not open for further replies.

Share This Page