Locations with pitch/yaw.

Discussion in 'Plugin Development' started by chaseoes, Sep 2, 2012.

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

    chaseoes

    I'm using this code:
    Code:java
    1. Location loc = new Location(world, x, 100, 3.5, (float)17.5, (float)0.5);
    2. player.teleport(loc);
    3. System.out.println(loc);
    The player is then teleported to the correct world, x, y, and z coords. However my setting of the pitch/yaw's have no effect and they end up facing a pitch of 0 and a yaw of 180.

    My debugging line on the bottom prints this out, showing that I have set them correctly:
    Code:
    Location{world=CraftWorld{name=world},x=-1.5,y=100.0,z=3.5,pitch=0.5,yaw=17.7}
    Anything I'm missing here?
     
  2. Offline

    Courier

    That's odd... I think I've seen this work for me before. By the way, you can just say, "17.5f," or, "17.5F," instead of, "(float)17.5"

    EDIT: Actually I've only seen this work by setting the respawn location in a respawn event... I've never tried it with teleporting.
     
  3. Offline

    escortkeel

    Yeah. You need to manually set the pitch and yaw as far as I'm aware.

    In that case, the code would be:

    Code:
    player.teleport(new Location(world, x, 100, 3.5);
    player.getLocation().setPitch(0.5);
    player.getLocation().setYaw(17.5f);
    Hear hear. Never cast to float like that. Not good. Also, by convention always use a capital F and not a lower case one. The reason for this is that when you use the letter L for long, the l and 1 look very similar in Courier New (almost indistinguishable).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  4. Offline

    chaseoes

    Courier escortkeel Figured it out!

    This code works, however I think I misunderstood how the yaw works? It seems setting it to 0 results in the yaw being 180, and after a couple hours I figured out that it was 185 if I set it to 5... so I simply added the yaw I wanted to 180 - and it works!

    yawIwanted + 180 = actualworkingyaw;

    Code:
            tploc.setPitch(30.50F);
            tploc.setYaw(226.10F);
     
Thread Status:
Not open for further replies.

Share This Page