- Home /
Get the root motion at a specific animation frame
Hey,
I'd like to know if there is a way for an editor script to get the (root) position of an object that is animated with mecanim using root motion.
Using gameobject.SampleAnimation or animator.Play changes the object attributes and local transform but doesn't update the position.
Thanks!
Answer by meat5000 · Feb 15, 2015 at 09:35 PM
This link will help you greatly, I imagine.
http://mecwarriors.com/2014/08/18/scripting-root-motion/
Essentially, Velocity = Displacement / Time.
You have velocity and time. Normalised Time is what you use I believe, for referring to a point in an animation. Which is basically between 0->1 Start to end.
Thanks a lot for your response meat5000. However what this article describes and the velocity is not useful to me. The problem is that I want an editor script that can jump to a specific point of an animation moving at the same time the object to the position that it would have gotten to if the animation was left to play without any interference.
Basically what I need to do is this: Let's say that you have a walkcycle animation that moves using root motion an object from point A at time 0 to point B when the animation is fully played. I need to know where the object will be at a certain time between time A and B without having to play the animation. deltaPosition is changed in every frame on the OnAnimator$$anonymous$$ove() so it can't help unless I play through the entire animation.
I'm not sure you quite get what I'm talking about.
The information you ask must be derived from the information you've got.
You know how long your clips are, you know your root motion velocity. This is all you need to work out your displacement (Displacement being the distance from a point in a particular direction).
Distance is a scalar. Its just a value. Displacement contains a direction which is why it works for what you want.
@$$anonymous$$ickBack one (rather complicated) solution might be to play the animation at start up, put the displacements and times in a lookup table and then you can interpolate the displacement for any time? Also the animation clips have an average velocity.. so a rough approach would be to say average_velocity * time / total_animation_time.
Your answer
Follow this Question
Related Questions
Root Motion On Slow Animations 0 Answers
Root Motion or CharacterController in FPS 1 Answer
Root Motion and Mecanim Speed ?? 0 Answers
Mecanim Root Motion + Networking 2 Answers
Get position from root motion? 0 Answers