zaterdag 18 februari 2012

Adapting animation in Unity

Adapting animation in Unity by rotating the bones looked like it was going to be easy in Unity. Mostly because one cna just rotate the bones in the editor and the effects are instantaneous. However, when trying to rotate the bones in the editor while 'the game' was running didn't have any effect at all. Also, trying to adjust the bones in a scripted way didn't seem to work.
After searching for a while at the unity answer forums and by looking at the head turning script provided in the asset store, it seems that Unity has a second update function called LateUpdate.

The update function used by the programmer in almost every situation is being called every frame. However, after the update function, unity takes over and applies some additional steps (preprocessing, shading, etc.). These steps include animation. So when we adjust a bone in the Update() function, unity will later override it. Enter the LateUpdate() function. This function is called after unity has had the opportunity to interfere. It is in this LateUpdate() function that the programmer has the opportunity to override decisions made by Unity. As a result adjusting animation and armature bones should be done in this function.

Geen opmerkingen:

Een reactie posten