Rotate Skull to face Location?

Discussion in 'Plugin Development' started by Dudemister1999, Jan 1, 2015.

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

    Dudemister1999

    Hello! I've got a skull, and I need to know how to make it rotate to face a location. I know some math is involved to turn 360 possible directions to 8 definite directions. Is there a one-line solution? It feels like there is, I just can't see it. Thanks!

    -Hydroxocoblalamin (OCHbl)
     
  2. Offline

    NathanWolf

    Hmm - well if you can get the yaw and then divide by 45 degrees ... maybe something like this would work out?

    Code:
    Location from = getFrom();
    Location to = getTo();
    
    // BLOCK_FACES is something you have to initialize yourself with the proper order of faces, since the
    // BlockFace enum is not in the order you want, you can't just use BlockFace.values().
    
    return BLOCK_FACES[(int)Math.floor(from.setDirection(to.toVector().subtract(from.toVector())).getYaw() / 45)];
    I would probably try to encapsulate some of that, though - one-liners are not always best :)

    A helper method that converts from a yaw value to a BlockFace, and maybe one to return the yaw between two Locations (there is probably a better way than what I did there) would make this cleaner and more manageable.

    Hopefully this is at least the right idea, though.
     
  3. Offline

    Dudemister1999

    @NathanWolf Looks like it should work! Easier than what I had in mind. :eek: I'll try it out once I get home! Thank you!
     
    NathanWolf likes this.
Thread Status:
Not open for further replies.

Share This Page