Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Offline tool to extracting position of bone at arbitrary points of anim

Discussion in 'Animation' started by jctz, Feb 12, 2016.

  1. jctz

    jctz

    Joined:
    Aug 14, 2013
    Posts:
    47
    Hi Gang,

    We're going to have units that throw projectile weapons at their victims. We want our game to be deterministic, so we can't rely on AnimationEvents firing on different devices to fire at the same time. What we need is an offline tool that extracts bone position information for each of our 'throw' animations, and then save that data off so it's readable by our game.

    So I know how read AnimationEvent instances from our clips to figure out at what point in our clip the projectile should be created. What I'm missing is how to - in an offline way - sample our skeleton at a certain spot in our clip, and grab the model-space position of an arbitrary bone. Has anyone had to do this before?

    Thanks,
    Jeff
     
  2. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    hey, I dont think this would be reliable either (to detect exact transform position).

    take a look at this simple script, which is an example of how to record transforms.
    http://forum.unity3d.com/threads/ikanimator.356586/

    but for this I'd use trigger collider (parented to the character capsule)
     
  3. jctz

    jctz

    Joined:
    Aug 14, 2013
    Posts:
    47
    Hey dibdab, thanks for your input.
    Over the weekend I came across AnimationUtility, which lets me extract curves for each of the transform properties (local pos, local rot, local scale) for every bone in the hierarchy. I then evaluated those curves at the desired time and got the pose I want. In short:

    EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(clip);
    AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, bindings[x]);
    MyCurveInfo[bindings[x].propertyName] = curve;

    ...
    float localPosX = MyCurveInfo["m_localPosition.x"].Evaluate(0.1f);