1
\$\begingroup\$

I am using Unity and need to know how to use it animation system properly for… well let me describe it below.

In this game I have this big 3D block-like character that moves in an unusual fashion compared to most game characters. In most games, the character moves along a straight line at a constant rate. However this character, and other characters in the game, does not move in a continuous fashion. Instead it is discontinuous and choppy in unique ways.

For example, here is how I want a big block character to move: enter image description here

Basically the two corners in front of him are pivot points, and the character moves forward by alternating between these two points and rotating. How can I do this with Unity's animation system? For the most part the animations in Unity don't move the character but instead have an animation play, such as the "Run" animation, and then a script actually moves the character. Know I the animator has a “use root movement” or something that does exactly this, but I have heard that it can causes problems. I’ve been considering just programming all of the animations, since they are relatively simple. However that makes fine tuning them a nuisance, and have some animations programmed and others not is probably not a good practice. I kind of also fear that if I don’t end up programming it I will have troubles with detecting if a character can walk through a certain walkway, considering for example the above animation his “walk width” is greater than his actual width since he rotates side to side.

Also keep in mind that there are other animations that are discontinuous like this but work in different ways. For example, another block that hops but pauses between hops. Another might rock backwards and then slide forward on the forward rocking animation.

So I know there are multiple ways to tackle this, but my question is what is the best way to do this? How would you do it?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I don't have access to the Unity docs at the moment and didn't do very much with the built-in animation system, so I might have the names wrong, but it's a keyframe system, yes? "At this time, this object should be in this state," and the engine handles the in-between? Use that for the rotations. At time 0, box should be level. At time 15 (or whenever), box should be rotated 15 degrees around top-left corner. At time 30 (or whenever), box should be rotated 15 degrees around top-right corner relative to previous keyframe. The important thing here is you have to keep moving the pivot between keyframes - it may be necessary (again, can't test at this moment) to add an extra keyframe (at time 1 and 16, in the above example) just for moving the pivot, or the engine might decide to move it slowly over time.

So (each of these is relative to the previous state):

  • T=0: Box rotation 0, pivot point centered.
  • T=1: Box rotation unchanged, pivot point at top-left corner
  • T=15: Box rotation +15 around X, pivot point unchanged
  • T=16: Box rotation unchanged, pivot point at top-right corner
  • T=30: Box rotation -30 around X, pivot point unchanged

Alternately, do you really need to make it an animation? Maybe make it actual movement. Comparable: A character who moves normally, their animation would be walking in place, while the model is moved horizontally by the game engine as a separate-but-simultaneous process. For this character, perhaps rotate the actual transform of the model - set the pivot point, rotate, repeat. In your example, the "script that actually moves the character".

It seems from your description that the unusual means of movement are actually a game mechanic, not purely cosmetic - generally, if you've got a game mechanic you want to handle it in the engine, i.e. with scripts, not in the animation system. There are probably exceptions, but they're not coming to mind.

Use animations for changes within a local frame of reference - if the box squishes or bends or changes color - but if the entire model is moving together, that's not a job for animation.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .