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
2
Question by SrBilyon · Mar 03, 2011 at 03:18 AM · animationpositionlocationsynccutscene

Syncing object's coordinate position with object's animation position.

I wasn't really sure how to word the question, so bear with me here.

So, let's say I give a player objects this "climatic" attack animation that involves him doing something crazy like jumping in the air and flipping from one side of an area to another. By the end of that animation, you would suspect that the player would land where even the animation ends.

However, the player would just end up in the position that the first frame took place. The same thing would happen if the player were to get hit during that animation (which of course would look terrible.)

So for my question: How can I move the object around with an animation that was exported where they player isn't staying in once place, and have the object's actual position sync with where ever he is during the animation? Most action games (such as kingdom hearts) use these "special attacks" where the players does 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 Alec-Slayden · Mar 03, 2011 at 03:25 AM 0
Share

if the animation is based on bones or other child objects of a group FBX, and your axis is the axis of one of these objects, you could potentially set your prefab's transform position to that root bone; but I haven't really dealt with this much myself, sorry if it doesn't help

avatar image Mill-Yahoo · Sep 08, 2011 at 07:23 AM 0
Share

Oh thanks! I've been finding this questions so long.

3 Replies

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

Answer by Ben 14 · Mar 07, 2011 at 07:33 PM

This is untested, but here's what I'd try:

public class RootMotion : MonoBehaviour { Vector3 m_storedPos = Vector3.zero; Quaternion m_storedRot = Quaternion.identity; Transform m_rootBone; // assuming this is set somewhere

 // lateUpdate is run after the animation has evaluated
 void LateUpdate()
 {
     // grab the local transform from the root bone as set by the animation
     Vector3 newPos = m_rootBone.localPosition;
     Quaternion newRot = m_rootBone.localRotation;

     // zero-out the root bone local transform
     m_rootBone.localPosition = Vector3.zero;
     m_rootBone.localRotation = Quaternion.identity;

     // apply the delta-transform to the player gameObject
     transform.localPosition += newPos - m_storedPos;
     transform.localRotation *= newRot * Quaternion.Inverse(m_storedRot); // not sure about the order

     // store the new transform for the next frame
     m_storedPos = m_rootBone.localPosition;
     m_storedRot = m_rootBone.localRotation;
 }

}

Comment
Add comment · Show 2 · 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 SrBilyon · Mar 11, 2011 at 04:03 PM 0
Share

Nice, I'm going to try it out once I get home. $$anonymous$$y HD failed a couple of days ago.

avatar image Ignite · Aug 01, 2011 at 12:26 PM 0
Share

This looks good. I tried it out. Not too sure about the line with transform.localRotation. The object snaps to a random position, albeit with the correct orientation. Any further insights?

avatar image
2

Answer by anomalous_underdog · Mar 08, 2011 at 03:29 AM

I also wanted to make something like this. The asset store has something:

http://u3d.as/content/mixamo/root-motion-controller/1sM

The Root Motion Controller allows you to control the speed of the character controller with the movement speed of the character's root joint!

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 SrBilyon · Mar 11, 2011 at 04:03 PM 0
Share

Thanks, I'm going to research this once I get home. $$anonymous$$y HD failed a couple of days ago.

avatar image
1

Answer by Statement · Mar 10, 2011 at 06:27 PM

You could have a transform in your animation that you sample at the last frame of the animation, that is where the next position of the character will be placed. This code isn't tested and I guess I am too lazy to open up a new project to try the script out on the construction worker. I did try it out on some animations I created with the animation editor though. I added a fully working class to Unify Wiki.

void Start() { // Assume we have an AnimationClip called attackClip.

 AnimationEvent syncEvent = new AnimationEvent();
 syncEvent.time = attackClip.length;
 syncEvent.functionName = "SyncAnimation";

 attackClip.AddEvent(syncEvent);

}

void SyncAnimation() { // Assume feet is a transform in your animation // that is placed where the character will be // at end of the animation.

 transform.position = feet.position;
 transform.rotation = feet.rotation;

}

Comment
Add comment · Show 4 · 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 Statement · Mar 11, 2011 at 01:29 AM 0
Share

I just tried this out myself and it seems to work fine, at least for my small setup. See full script http://www.unifycommunity.com/wiki/index.php?title=AnimationStepSync

avatar image SrBilyon · Mar 11, 2011 at 04:04 PM 0
Share

I'm going to play with this once I get home. $$anonymous$$y HD failed a couple of days ago.

avatar image Statement · Mar 11, 2011 at 04:57 PM 1
Share

I'm sad to hear that.

avatar image SrBilyon · Mar 11, 2011 at 10:35 PM 1
Share

Yeah, sad thing was, it was a 10 dayold WD 2TB.

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

2 People are following this question.

avatar image avatar image

Related Questions

How do I make mecanim animations respect bone location/position keyframes? 0 Answers

How can i allign 2 animations of 2 gameobjects perfectly in sync? 0 Answers

Have Camera To Move To Specific Position 1 Answer

animations or code? 1 Answer

Play Audio in Animation Window 0 Answers


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