Solved Set Entity Yaw

Discussion in 'Plugin Development' started by thebiologist13, Mar 14, 2013.

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

    thebiologist13

    Hello All!

    This is probably going to turn out incredibly obvious, but how do I set the yaw (i.e. rotation or direction looking) of an entity? Currently, I use this:
    Code:java
    1. Location spawnLocation = new Location(someWorld, x, y, z);
    2. spawnLocation.setYaw((float) (Math.random() * 360.0d));
    3. someWorld.spawnEntity(spawnLocation, EntityType.ZOMBIE); //Zombie is just an example, I change it up.


    This method always spawns them facing North though. :confused:

    I also tried putting some debug output for the "Math.random() * 360.0d" part to verify it was giving values between 0 and 360 degrees, and it was.

    Am I missing something? Or is yaw in radians or something like that?

    Thanks in advance! :D
    ~thebiologist13
     
  2. Hmm, I belive spawnEntity() doesn't care about the angles of location.

    The only way you can change pitch/yaw of an entity is by using teleport.
    There is a http://mc.kev009.com/Protocol#Entity_Look_.280x20.29 packet but you'd have to use CB/NMS code for that (or ProtocolLib).

    But for your code using teleport would be just fine since you just spawned the entity.

    EDIT:
    Also, instead of using 360.0d and casting to float why not use 360.0f ? :p
     
    thebiologist13 likes this.
  3. Offline

    thebiologist13

    Thanks so much! This worked perfectly. :D

    I changed it to this:
    Code:java
    1. Location spawnLocation = new Location(someWorld, x, y, z);
    2. spawnLocation.setYaw((float) (Math.random() * 360.0d));
    3. Entity entity = someWorld.spawnEntity(spawnLocation, EntityType.ZOMBIE);
    4. entity.teleport(spawnLocation);
    5.  


    Also, I was using 360.0d instead because I put the "Math.random() * 360.0d" in a separate "randomRotation()" method that returns a double. I suppose it could return a float though. :)






    Thanks again!
    ~thebiologist13
     
Thread Status:
Not open for further replies.

Share This Page