Entity's Yaw

Discussion in 'Plugin Development' started by 97WaterPolo, Oct 15, 2014.

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

    97WaterPolo

    I have spent the past hour trying to determine how the yaw of a mob works. I clearly did not do so good. I am trying to get the mob's faceing direction head on, dead center, on North, South, East, West, but that clearly isn't working at the moment.

    Currently I am using
    Code:java
    1. Location spawnLocation = new Location(Bukkit.getWorld("sao"), 51, 71, -59);
    2. spawnLocation.setYaw(90F);
    3. s.getBukkitEntity().teleport(spawnLocation);


    I am assuming NSEW, one of them would be 90 as 360degree FOV / 4 direction = 90. If I try 89.5 vs 90 vs 90.5, it is all still off by a bit. I need to find a way to set it dead on, I kinda wish I can use BlockFace to get the value but I don't believe you can.

    Any help would be greatly appreciated with setting the yaw.
     
  2. Offline

    teej107

    97WaterPolo Are you sure it's not just the way the mob's model is rendered? Have you tried it for yourself? You could also debug by printing the mob's yaw after you teleport it to make sure the yaw is still at the desired direction.
     
  3. Offline

    97WaterPolo

    teej107
    Yep, I tried out printing the yaw, the value is what I set it to. You can easily see that the mobs render is not facing the direction head on, its slightly left or right of the direction.
     
  4. Offline

    teej107

    97WaterPolo Try setting the yaw after you teleport the entity. I assume you are using NMS. Are you sure there isn't any code you did with the NMS entity that is causing this to happen?
     
  5. Offline

    97WaterPolo

    teej107
    Positive, I am setting their position, which only takes XYZ, then 3ticks later I teleport them to a location while setting the yaw with the above method. I will try again, but any chance you have the degree reference for the directions? Like N = 90° and S = 180° etc?
     
  6. Offline

    teej107

  7. Offline

    TheCodingCat

    if you want to set the entities yaw without teleporting or anything, I used this for my Mob rider plugin
    Code:java
    1. @param e = Entity you want
    2. ((CraftEntity)e).getHandle().yaw = some double
    3. // thats all you do and it turns.
     
  8. Offline

    97WaterPolo

    teej107
    I am guessing that returns 0 1 2 3 4, how would I convert that to degrees, I doubt loc.setYaw(4); would actually set them facing a direction. Also, thanks for all the help :p
     
  9. Offline

    teej107

  10. Offline

    Europia79

    97WaterPolo

    interesting problem.

    Did you remove all the PathFinders from the mob ? Otherwise, once you teleport, one of the pathfinders might make the mob look at a different direction. Also, did you try what TheCodingCat said ? And set the yaw field of the mob directly ?
     
  11. Offline

    97WaterPolo

    Europia79
    All path finders are 100% removed. I didn't see TheCodingCat's post, will try now!

    TheCodingCat
    I am currently trying that, I removed all the teleporting code, current one is:
    Code:java
    1. Location l = player.getLocation().clone();
    2. l.add(.5,0,.5);
    3. s.setPosition(l.getX(),l.getY(), l.getZ());
    4. ((CraftEntity)s.getBukkitEntity()).getHandle().yaw = yaw;


    For some reason when I do this, all the entities are facing South, no matter what I set the yaw to. The closest so far I have been was teleporting the entity to a location, but it doesn't actually set the alignment perfectly straight, and unfortunately, my OCD kicks in and I can't look at it without getting angry. Any other suggestions?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  12. Offline

    TheCodingCat

    Again 97WaterPolo
    Code:java
    1. ((CraftEntity)e).getHandle().yaw = YourRequestedYaw;
     
  13. Offline

    97WaterPolo

    TheCodingCat

    ((CraftEntity)s.getBukkitEntity()).getHandle().yaw = yaw;
    vs
    ((CraftEntity)e).getHandle().yaw = YourRequestedYaw;

    What am I missing, as I clearly don't see it. Your e, is my s.getBukkitEntity();, yaw is a variable that is declared in the constructor.
     
  14. Offline

    teej107

    97WaterPolo It's usually not a good idea to modify values directly. It is better to use setters. Here is a list of setters that I saw. One of them seems to be a method of interest. I assume its arguments are the same as setPosition() except with yaw and pitch arguments added.
    [​IMG]
     
    97WaterPolo likes this.
  15. Offline

    97WaterPolo

    teej107
    Well originally I tried setLocation, which would take the yaw and pitch, and that wouldn't work. I will try the rotation and see if it does :)
     
Thread Status:
Not open for further replies.

Share This Page