Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by PrimeDerektive · May 08, 2011 at 02:55 AM · animationtransformbone

Capture positions and rotations of all bones at a specific frame of an animation clip

In Start(), I'd like to somehow play the first frame of a particular animation for my character model and then capture all the positions and rotations of the bone's transforms in arrays, without the animation actually visibly playing (I just need that information for later, but I don't really want to visibly play this particular animation at Start()).

Any ideas on how I might accomplish this?

Comment
Add comment
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

1 Reply

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

Answer by Paulius-Liekis · May 08, 2011 at 09:47 AM

You should do this: sample the frame on the animation you want, then restore character pose to the previous one.

You can sample you desired animation by doing something like this:

AnimationState state = animation["name"]; state.weight = 1; state.enabled = true; state.normalizedTime = 0; animation.Sample();

// extract the desired transforms

// get all child transforms Transform[] transforms = animation.gameObject.GetComponentsInChildren<Transform>();

// Collect position of all transforms (declare this dict somewere where you can access it later) Dictionary<Transform, Vector3> positions = new Dictionary<Transfrom, Vector3>(); foreach (Transform t in transforms) positions.Add(t, t.localPosition);

// restore previous pose (by either sampling another animation, // or saving and restoring transform values) animation.Stop(); animation.Play("Run");

Restoring positions later:

foreach(KeyValuePair<Transfrom, Vector3> entry in positions)
{
    entry.key.localPosition = entry.value;
}

Obviously you want to store positions and/or rotations and maybe scale. Depends on what you do.

Comment
Add comment · Show 5 · 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 PrimeDerektive · May 08, 2011 at 01:54 PM 0
Share

I thought about using Sample(), but I have no idea what it actually does and the docs seem deliberately scarce. What do I do with it once I've sampled it? Where do those transform values and whatnot get saved to?

avatar image Paulius-Liekis · May 08, 2011 at 10:53 PM 1
Share

Transform values are saved on the object itself (i.e. on object transforms), which means that if you do not restore values of transforms then the character will be rendered in that pose.

avatar image PrimeDerektive · May 08, 2011 at 11:14 PM 0
Share

The previous pose is not an animation though, so I'm not sure how I will utilize Sample()... in short, I have an animation called "getup" that is the character standing up from a laying position. When the player is knocked down I simply enable all the kinematic rigidbodies on his bones, then from whatever position he settles in I want to crawl his bone hierarchy and disable the kinematics, then lerp the positions and rotations to the first frame of the getup animation. Does that make any sense?

avatar image Paulius-Liekis · May 09, 2011 at 03:29 PM 0
Share

Yes, that makes sense. I do such things every time need to blend between animation and ragdoll. You just have to store "get up" pose and then use it for lerping.

avatar image PrimeDerektive · May 10, 2011 at 02:15 PM 0
Share

I still don't understand how to use the Sample() data though. One I Sample() the get up animation at the first frame, where is that bone transform data stored so I can lerp the ragdoll bone transforms to those positions? Can you expand your example code a little bit to show how to use what you Sample()?

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

No one has followed this question yet.

Related Questions

No tranform animation on root bone from maya.mb 6 Answers

Can I get a the transform from a bone animation? 0 Answers

Attaching an object to an ongoing animation 1 Answer

Manually set transform on certain bones in skinnedmeshrenderer 1 Answer

Added rotation AFTER the rotation from animation clip ( rewarding 400 points to whoever solves this) 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