There are two basic ways for animating a character:
A. get in place loops and procedurally move the character.
B. use animations which includes motion of the root node (including translations) and chain them together.
A is easy and supported by Unity.
B is better quality but there is no direct support.
Many many people posted about this problem. The solution seems to be to parent a gameobject and use that to reset global position at the end of the animation loop.
How do I do that? What kind of function calls should I use? Thanks for any help, I promise I will post the full solution.
Thanks!
Stefano
Well, the usual technique is to put the empty gameObject inside the joint for the dead center of the body. Then, at the end of the animation, the new round is started with the master gameObject centered on that location.
If you put the empty inside the master object, it’ll follow the object, but not the animating mesh that’s moving forward.
thank you, I totally get that.
the point is in practical tewrms how does it work.
Here I have a simple simple example. I will also look at your tutorials if I can get this simple example to work. Thanks!
Stefano
hierarchy of my character: gameObject > character > Reference > Hips …
this is a mini-script I run on character:
function Update () {
if (Mathf.Abs(Input.GetAxis(“Vertical”)) > 0.2){
animation.CrossFade(“startwalk”);
// here is the part where I need to read the //transform of the startwalk animation and
//move the parented gameObject to the new location //so that the next animation “walk” starts from there. //startwalk and walk would chain one after the other.
animation.CrossFadeQueued(“walk”,0.1, QueueMode.CompleteOthers);}
else
animation.CrossFade(“idle”);
}
You can’t use cross-fading with this approach, since it would cross-fade the global position too. You need to code the animation state changes in such a way that you can monitor when new animations start and apply the offset at that exact time.
Rune
Thanks Rune.
So the current test I ran is this (not using crossfade anymore), trying to update the parent node in between animations. It doesn’t seem to work though.
Thank you for any help you can provide!
Stefano
hierarchy: Global_Node → Reference → Hips
function Update () {
if (Mathf.Abs(Input.GetAxis(“Vertical”)) > 0.2){
animation.Play(“startwalk”);
animation.Stop();
Pxyz=GameObject.Find(“Hips”).transform.position; Pxyz.y=0; GameObject.Find(“Global_Node”).transform.Translate(Pxyz);
animation.Play(“walk”);
}
else
animation.CrossFade(“idle”);
}
Code inside the Update () function will be executed each frame, so basically, in each frame you are starting the “startwalk” animation, stopping it again, and starting the “walk” animation (as long as the vertical input axis is above a certain threshold). I would expect that this is not what you want.
Instead, only start new animations when the previous one is done playing (check if its time is larger than its length) and only apply the offset there.
It seems that Adam made a script to solve the problem already:
http://forum.unity3d.com/viewtopic.php?p=107746#107746
Rune
Thank you Rune for the help.
Adam’s solution doesn’t seem to work properly.
I guess at this point it would be useful just to be able to chain together loops of the same animation. That will be the baby step from which we can develop more elaborate scripts.
I tried detecting the end of the end of the loop
if (animTimer >= currentLocatorAnimation.length)
and then updating the position of the parent object using the value on the Hips of the character. No matter what I do the next loop will start back from the initial position. I really tried a bunch of stuff.
Any help in putting together the basic procedure of concatenating loops would be very much appreciated.
Thanks!
Stefano
Why? How does it not work? How have you set it up and how are you supplying the new animations that the script require you to assign? Just saying “it doesn’t work” will rarely let people come with any useful suggestions.
The script Adam posted already supports that as far as I can see, and it already is the help you are asking for. I don’t see the point in creating yet another script when there is already one available.
Rune