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

Models change position when animations play

Discussion in 'Animation' started by Benjamin Magnus, Feb 26, 2014.

  1. Benjamin Magnus

    Benjamin Magnus

    Joined:
    May 23, 2013
    Posts:
    40
    To start off Ill admit Im a total beginner when it comes to dealing with animation. Ive got a little machine gun turret who's barrels rotate and gears move when it has a target in range. the animation is as simple as can be. But for some reason when the animation plays in Unity the part of the model that's animated flys upwards around 3.5 units and plays dangling up in the air in akward fashion. Im at my wits end trying to figure out when its doing that, if anyone has any insight it would be greatly appreciated.
     
  2. Alf203

    Alf203

    Joined:
    Dec 7, 2012
    Posts:
    461
    I'm going to go guess that you have animated the parts separately as separate gameobjects and if you do that they need to be animated relative to a parent object which isn't your case. So what I am saying is that you probably animated the turret inside Unity at a certain spot (x,y,z), well when it plays it goes to that position to play the animation. So when you place the turret in another (x,y,z) that part moves to where it was when you created the animation.

    However, its just a guess.

    You need to write more details or post screens if you want help. Is it skinned or are they separate objects; how did you animate it, does it look fine in preview, are you using generic or legacy, etc.. ?
     
  3. Benjamin Magnus

    Benjamin Magnus

    Joined:
    May 23, 2013
    Posts:
    40
    You are right about my animating seperate objects, as the housing the gun sits in just lerps towards and empty game object that is always looking at the target, to achieve a simple and smooth turn. I animated it in blender with just a few keyframes recording its rotation. Yes, it looks perfectly fine in the preview, and the transitions in the animation controller look good to (the only transitions being from idle to rotating and back).

    Edit: So this morning I managed a work-a-round for my problem. I just animated the rotation of the barrels, not skinned, as a separate object, with its location at 0,0,0 (rather than in its normal position in the model). Then exported the barrels and the rest of the model as separate objects. Then in Unity made the barrels a child of the main bit of geometry and attached the animator to the barrels along with a small script to register when the parent has a target it can fire on. Works perfectly. I do realize that this will only work with very basic animation so I still have some work to do on figuring all this out.
     
    Last edited: Feb 26, 2014