- Home /
Head Rotation while Animation is played
Hello there,
I'm working on a small 3d multiplayer game where the head rotates with the camera. so if you look down your character looks downward too and the others can see it.
However when i do that all animations stop.
In the Project is just a Scene with a flat terrain and the Character so far.
The character looks like the one in Minecraft and has an armature with Torso,Head,Leg,Arm bones. All bones are conncted to the Torso.
The Animations were made with the Unity buildin Animator and are played with bools inside the Animator, which are controled by a simple if(input) walkanimation = true; script.
The Character is using the standard First Person Controller along with the MouseLook script that unity has as a standard asset.
I've tried several approaches, but none really work.
1st approach:
Made the Camera the Head-bones child. So it moves with the Head.
Change the Object, that is moved by the MouseLook script to the Head instead of the Camera.
outcome : Head moves properly, character walks, but animation stops as soon as the player moves the mouse.
2nd approach:
Made the Camera the child of the characters-main-object . it Doesn't move the Head but inherits the Y rotation and the position.
MouseLook Script Moves the Camera.
attached a new script with the following code to the head
transform.eulerAngles = new Vector3 (Camera.main.transform.eulerAngles.x,Camera.main.transform.eulerAngles.y,Camera.main.transform.eulerAngles.z);
outcome : Head moves properly, character walks, but animation stops as soon as the player moves the mouse.
3rd approach:
- don't use the Uniy Animation system and instead Program a script that does the whole animation with .Lerp functions. VERY TIME CONSUMING....
Made the Camera the child of the characters-main-object . it Doesn't move the Head but inherits the Y rotation and the position.
MouseLook Script Moves the Camera.
attached a new script with the following code to the head
transform.eulerAngles = new Vector3 (Camera.main.transform.eulerAngles.x,Camera.main.transform.eulerAngles.y,Camera.main.transform.eulerAngles.z);
outcome : Head moves properly, character walks, "animation" is played properly. so it acutually works, but consumes way to much time to do several animations like this.
Conclusion:
If while playing an animation a script changes the rotation of a bone, all animations stop. Because the Script seems to have higher priority than the Animation does.
possible fix:
change the priority order.
find a script command that doesn't stop the animations
find another way that doesn't interfere with the animtions
... But i have no idea how to do any of this.
the second link seems to be the exact same thing i want to do.
the first link however well it seems interesting too but 2 of those links lead to empty pages ...
the link to the example projects leads to the unity download page
and the link to just have the script leads to a page that is selling its domain or something...
its still in interesting forum post and ill read it in detail tomorrow and of course the first one will most likely help me too !
thanks a lot i really appreciate your help!
Answer by Cherno · Jan 25, 2015 at 08:04 PM
You canshould be able to do it like this:
Instantiate an empty gameobject at the neck bone's position. Make the head bone a child of this empty GO. The bone hierarchy is now broken at the head, But that doesn't matter. Use AddMixingTransform[1] to give any (preferably empty, meaning no head movement taking place) animation clip the head bone transform. Play the animation just to be sure. The normal move etc. animations should work as usual until they reach the neck.
It will probably require A LOT of trial and error, I know because I spend more than a week IIRC getting this to work. For my project, I wanted a character to get into a shooting pose, and then turn the torso towards the target and play the shooting animation for the torso only. It's a mess with parenting/unparenting, Add/Remove MixingTransforms, Animation.Play and CrossFade... But in the end it works. Maybe you can even use layers?
[1]: http://docs.unity3d.com/ScriptReference/AnimationState.AddMixingTransform.html
Answer by jeromeWork · Feb 01, 2017 at 02:52 PM
Just adding the gameObject to break the bone hierarchy works great for me. Thank you.
Your answer
Follow this Question
Related Questions
Rotation of the fps camera doesn't work in game when animated 0 Answers
Having Trouble animating camera at start of game 0 Answers
FPS camera inside player model 0 Answers
Why wont my camera controller work,Why isnt my script working for a camera controller? 1 Answer
How to fix main camera moving with animation of parent player object? 1 Answer