- Home /
How to Animate Environment Objects
I have been tasked with making a playable environment within a game engine for a class project. I am new to Unity, although I have been watching tutorials and using it for a few weeks. I have several years of experience working with Maya, and I have a basic understanding of the workflow between Maya and Unity. I already have environment objects completed with animation and have assembled the scene in Unity. The ambient objects that only require a portion of the object to rotate or translate work fine, such as a fan or a flag. However, when it comes to objects that move within the environment, I am not sure on the best approach to animation. I have a basic understanding of Mechanim, but I am not certain how this applies to animals or organic environment objects.
I have a crow with a basic wing flapping animation that I want to circle overhead in a loop. Would it be best to animate the translation and rotation using Unity's tools and leave the Maya animation for the wing flapping?
In addition, I have an animated tumbleweed with a rotation and translation that I want to roll from one corner of the terrain to the other. However, the Maya animation only covers a short distance and looping the animation returns the object to its original location in 3d space to start again. Would I need to extend the Maya animation to cover the length of the level or is there a more efficient approach?
What is the best approach to animating environmental objects within Unity?
Answer by Kiloblargh · Jul 04, 2013 at 08:43 PM
The best approach IMHO is to animate as much as you can with scripting. If something will be moving in a fixed way, you should animate its looping behavior relative to its own center and then move that center with an animation curve in Unity.
But It sounds like you're still thinking inside the pre-rendered 3d animation box from your years of Maya experience.
The crow can come and go, it can perch on a tree and be scared off when the player arrives. The tumbleweed doesn't need to roll across from point A to point B and loop; you can make tumbleweeds of all sizes and colors spawn randomly and roll by using rigidbody physics or even a particle system.
If the crow's circling, it shouldn't look like it's a stage prop hanging from a mobile, it should be rising up one thermal and swooping to catch the next.
All this is more work, but it's what Unity does well that Maya doesn't. If the point of the class is creating interactive environments; the behavior of every entity you put in that environment is very important: do they even have behavior, or is it essentially just a short film that you can walk through?
Thank you for your feedback. I see that these animations would be better as scripts than as pre-rendered animations. Do you have any links to resources that might cover this type of behavior?
These objects do not have to be interactive. They are considered ambient entities for the purposes of the class. Other objects such as moving platforms have to be interactive, but I have already created scripts to trigger these animations based on the player's proximity. The assets in question are merely for the aesthetic value.
You can quickly get what appears to be complex behavior with well-constrained randomness. Invoke and InvokeRepeating, Random.Range, and switch / case statements are all you really need as a beginner; that and an unlimited supply of coffee. But the basic idea is that any variable you could hand-set in the inspector, you could just as easily roll the virtual dice on at runtime.
Does the following make sense to you?
function RollTheDice ()
{
var roll : int = Random.Range (0,12);
switch (roll)
{
case 0:
DoThis();
break;
case 1:
DoThat();
break;
case 3:
case 4:
case 5:
DoSomethingElse();
break;
}
Invoke ("RollTheDice", Random.Range (0.2, 2.0) );
}
Yes, this is great. I ended up creating simple scripts for translation and rotation for the purposes of my assignment, but I will keep this in $$anonymous$$d for more complex behavior. Thank you for all of your help!