Friday, 24 July 2015

Entity Rotations and Animation

This post is just some notes about Entity Animation and Rotations which I had to learn the hard way and might be of interest.

If you are using an EntityLivingBase, it has a few key variables which determine where it is rendered and which way it is facing.  An EntityLivingBase usually has

  • a body which can rotate left<-->right ("yaw"); and
  • a head which can rotate left<-->right ("yaw") and tilt up<-->down ("pitch")

Minecraft variables used for head orientation.

  • The position of the Entity is given by posX, posY, posZ, which corresponds to the centre of the body, at the entity's feet.  In order to get the entity's eyes you need to add Entity.getEyeHeight() to the Y position.
  • EntityLivingBase uses four variables related to the rotation of the Entity:
  1. rotationYawHead, which indicates which way the head is pointing left<-->right.  0 degrees is south and increases clockwise.
  2. rotationPitch, which indicates where the head is looking tilting up/down.  0 degrees is horizontal, -90 is up, 90 is down.
  3. renderYawOffset, which indicates which way the body is pointing, similar to rotationYawHead.  It is used for rendering.
  4. rotationYaw, which indicates which way the body was pointing when it last moved.  This is similar to renderYawOffset, however it is used in different ways not directly related to the way the entity is rendered.
In most cases, these variables are updated in a couple of key methods & classes
  1. EntityBodyHelper (deobfuscated version here) is used to update the body and head rotations:
    a) if the entity is moving, the body is instantly rotated to the direction of movement (rotationYaw).  The head yaw is rotated if necessary to match the body yaw within +/- 90 degrees (i.e. the head must not be twisted past the shoulders)
    b) if the entity is not moving, after a short delay the body is slowly rotated to the direction that the head is facing (rotationYawHead)
    This code is executed on both client and server.
  2. EntityLookHelper is used by AI on the server side to update the head yaw and pitch:
    a) If the entity is looking at a target (another entity, or an [x,y,z] location) then the method sets the head yaw and pitch appropriately
    b) If the entity is not looking at anything, the method slowly returns the head yaw to match the body yaw.
    If the entity is moving, it will also constrain the head yaw to be within +/- 75 degrees of the body yaw.
  3. EntityMoveHelper is used by AI on the server side to set the rotationYaw.
The variables are synchronised occasionally from the server to the client, using for example

When rendering, the variables are used as follows:

doRenderEntity(Entity entity, 
               double x, double y, double z, 
               float rotationYaw, float partialTicks, 
               boolean showOutline);

this then calls the Entity Renderer:

doRender(Entity entity, 
         double x, double y, double z, 
         float rotationYaw, float partialTicks);

This method 
  1. rotates the rendering frame by renderYawOffset
  2. calculates the 'netHeadYaw' (the angle between the head yaw and the body yaw) and then calls setRotationAngles() for the main model (ModelBase)
  3. calls ModelBase.render().
LimbSwing and LimbSwingAmount are animation parameters/timers used for animating the leg positions properly when the entity is moving.


setRotationAngles(limbSwing, limbSwingAmount, ageInTicks,
                  netHeadYaw, headPitch, 0.0625F, entity);
// 0.0625F is a scaling factor

render(limbSwing, limbSwingAmount, ageInTicks,
                  netHeadYaw, headPitch, 0.0625F, entity);
// 0.0625F is a scaling factor

Although rotationYaw is passed to the RenderLivingEntity, it doesn't use it for rendering the model.  It is used when rendering some other Entity types, or (for example) when rendering name labels.


  1. YOu are talking about the pitch at the beginning ... but I see that it is never passed to the doRender and doRenderEntity methods. I created a fish mobs, which rotate perfectly, but I was never able to adjust the pitch. I am hunting that thing for months.

    1. Hi
      I'm not sure I understand exactly what you mean. Perhaps you are getting head pitch and body pitch mixed up?
      Only heads have pitch; body doesn't have pitch. If you want your fish body to have pitch, you will need to add custom code inside the renderer you use for the body.

  2. Betting is easy with the internet.
    รอยัล1688Online gambling games are open to the players to gamble indefinitely. The online casino of the site that makes the player happy with the risk of multiple online casinos. With easy access to online casino games through internet gambling. There are several ways to get players to gamble with us. The risk of online horoscope has increased. Today's online games can meet the needs of the player. Because there are types of online gambling games that are easy to understand, and online games to win more than 100 games to enjoy a full size because you do not have to travel to the casino. Because they can use online services and can earn money from the real risk. Not only this, the online game also broadcast live betting, so it is like betting from a real place. If you are one of the gamblers who want to gamble, the next step is to go online. And can meet all needs. Online Gambling Betting is the Way to Choose Who I came to the risk. Have you ever been here today? viva3388

  3. Make Money From Playing Online Casinos
    Gclub SlotIt is a site that offers online casino games with a reputation for being fun, open, fun and fun for more than 10 years, making the casino known and accepted by the time. Not long for playing games, gambling online is one of the beginning of wealth. Anyone who can join and start rich is not difficult. Because online gambling is a form of online gamble, gamblers or ordinary people become the highest earners in the country and the highest in the world because of their income from gaming. Online casino is very easy. Since every time a gambler defeats an online gambler, the gambler can make money from playing online gambling games as well. Just bettors join in the fun and play casino games. Online Our online casino player can make a profit from playing casino games online with the gamblers around the world if you want to know that the income from playing online gambling games are very. How much risk can be challenged by the Bet on the WebHoliday Palace

    Royal1688  To join the casino online is currently a region of solid service has been very popular among gamblers around the world to enter into quality gambling and a large collection of casino games. To support the needs of the player as well, it is considered a financial channel that most people in the response and attention to the best casino gambling. Online quality and the most popular games that will play baccarat is a gambling game that can make a profit for the player easily or not to play high quality online. Gamblers enjoy the fun of playing a variety of games to make a profit for the players are sure to play online slot. Gambling games that make the player to bet fully and do not make the player has to travel to foreign casinos, they start to enjoy the best bet with the stability and quality can make the player. Get involved and experience the opportunity to gamble all kinds of casino games that are available to players to effectively bet with online casinos.

  5. New fun with online casinos.
    Ruby888The online gambling games site will create all the joy and excitement for the players. We have launched online gambling games that are rich. In order to meet every need, each person has the opposite demand. Use the online game to win real money and give you an advantage. All games are available to players at risk without interruption with the service throughout. The choice of entertaining bets is not boring. Online gambling games that users can choose to gamble as you like. Online casino games with sites. And online gambling games that give users a chance to win chance. It is a great way to make money online. If you want to gamble online games that are ready to make you money with gold shortcuts. Whether it is the type that can create fun and benefits to customers. I do not want the chance to gamble online gambling games most of the festive. To make money, you have the advantage to enjoy many pleasures. Play as you like. IBCbet

  6. Fun casino you should not miss.
    GclubIs a web casino Asia's leading online gambling establishment for more than 10 years, with a modern and attractive service system, makes it easy to gamble online at the casino site. This club has been And is of interest to Asian gamblers. Since online casino site providers are open with honest and transparent services and continue to develop online gaming services, the risk is always online, so it is not uncommon nowadays to play online casino games. It is very popular among Asian gamblers, the bettor can come and meet the atmosphere of the game. These online gambling players just got easier with Wi-Fi only. Bets can also be played at any online casinos on the casino site. Our club. The easy and easy access to online casino games is very popular and when a player has problems during the game, online gamblers can contact our staff at any time. Betting on the web Royal1688

  7. Very helpful suggestions that help in the optimizing topic,Thanks for your sharing.


  8. Enjoy with online casino 24 hours service.
    Goldclub SlotBetting online casino games that you have fun with online gambling fun filled with joy. Win a new online look, which will make customers enjoy the service. Along with the game of online lucky draw. The choice of modern online gambling bets. Online games to play lucky hundreds of games to enjoy. In the latest online gambling games like the gamblers around the world. Because they can bet richly and earn money from the game. The atmosphere of online casino games is more realistic by live casino games online. With sharp images, play without interruption. Gambling Online Gambling is a great way for players. Not only this, but also can find other entertainment and entertainment with other consumers. Do not stop to provide free online games that meet the needs of users. If you are interested or are looking for a way to make extra money to you. Win a game online is a way to meet all your needs. คาสิโนออนไลน์