Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How can I offset weapon position based on bone position during animation?

Discussion in 'Animation' started by samDawg, Nov 28, 2018.

  1. samDawg

    samDawg

    Joined:
    Sep 23, 2017
    Posts:
    2
    Hi everyone, this is my first post here. Currently I have a combat animation done in maya. The weapon is also animated with a locator, position constrained to the wrist bone, and the locators rotations animated.

    I have trouble with getting the weapon into the right position when it's imported into unity because the weapon is not aligned to origin. So I tried moving the weapon to origin and only exporting it's rotation animation and do the position in unity by getting wrist bone position. The weapon is then parented to the character group not the wrist bone to preserve its rotation. I used a script to set the weapon position to match wrist bone position each frame during gameplay. This works fine but it needs to be offset a little to match the hands.

    So the position I got from maya is an offset from the wrist bone because the locator is set to (0,0,0) at the wrist bone. In Unity, I'm trying to reverse this offset to get the weapon's position in the character group space relative to the root bone position. I can achieve this by adding the value of position animation each frame to wrist bone position each frame. However, I don't know how to extract the position data from animation to add them together at the right time. Also I found out that it's not possible to access animation data during runtime. Is there anyway I can achieve this or any workarounds I can try?

    Sorry if this is a bit unclear. I'm trying my best to explain it. Hope you guys understand. Thanks!
     

    Attached Files:

  2. teutonicus

    teutonicus

    Joined:
    Jul 4, 2012
    Posts:
    70
    Unity supports https://docs.unity3d.com/Manual/Constraints.html these days. Make sure you're exporting them to fbx correctly and they should just work, removing the need for the custom stuff that you're currently doing. Parent your weapon GameObject to the now constrained locator and bam.