Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Kacheek · Nov 09, 2014 at 04:55 PM · animationcameracamera-lookhead

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:

  1. change the priority order.

  2. find a script command that doesn't stop the animations

  3. find another way that doesn't interfere with the animtions

... But i have no idea how to do any of this.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Chris333 · Jan 25, 2015 at 07:54 PM 1
Share

Hi,

could that maybe help?

http://forum.unity3d.com/threads/head-look-controller.26318/

http://answers.unity3d.com/questions/126368/how-to-rotate-a-bone-during-an-animation.html

avatar image Kacheek · Jan 26, 2015 at 12:10 AM 0
Share

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!

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kacheek · Jan 26, 2015 at 12:03 AM 0
Share

Hello, Thanks a lot ! i will try that out tommorrow!!!

avatar image
2

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges