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. Dismiss Notice

Accessing child object animations in .blend asset

Discussion in 'Animation' started by OJDee, Oct 10, 2016.

  1. OJDee

    OJDee

    Joined:
    Feb 11, 2014
    Posts:
    64
    Hi

    I have a tank modelled in Blender, imported just through its .blend file.
    The model is broken into several meshes, specifically the turret has a child mesh for the gun barrel.

    I have a simple three keyframe animation for the barrel to slide into the turret and back, recreating a recoil effect. In Blender, if I rotate the turret to any angle and drag the animation control, the barrel slides in and out as expected.

    However when I try to play the animation in Unity, the turret always snaps to zero rotation before barrel slides in and out. It appears that the barrel animation has captured the turret location somehow and reverts it to zero when barrel is animated.

    I am accessing the animation with this code:

    Animation animation = transform.GetComponentInChildren<Animation>();
    animation.Play("Fire");

    How can I play animation on a child without the parent being affected?

    Thanks
    Oli
     
  2. GrischaG

    GrischaG

    Joined:
    Apr 26, 2013
    Posts:
    40
    Hi,

    for this task you should use an AnimationController and different Layers for the parts of your tank.
    Use the same hierarchy and choose the layers to be additive.

    Grischa