Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Animation Clips and Local space

Discussion in 'Animation' started by matbrummitt, Nov 24, 2013.

  1. matbrummitt

    matbrummitt

    Joined:
    Jan 12, 2010
    Posts:
    107
    Hi all,

    I am trying out Unity animations for the first time, and having a spot of bother here.

    Basically, I have a canon which will have a number of animation states on it, such as idle, powering up and firing. When firing, the barrel will animate forward and backward in X, to give a feeling of blast power. The animation is fine when the barrel is aimed horizontally (default position) but if aimed upward or diagonally for example, the animation is in world X, so obviously isn't what I want.

    How do I set it up so that animations are in local coordinates, and not world? I read somewhere that you should make it a child game object. However, it already is. I have a "cannon" parent object which holds all the various cannon pieces (Barrel, Base, Exhaust and Feet).

    I've attached a screenshot of my cannon (from the preview pane), the hierarchy of cannon pieces and another preview pane showing the issue.

    Thanks

    Mat
     

    Attached Files:

  2. Shinugami

    Shinugami

    Joined:
    Oct 17, 2012
    Posts:
    54
    I have the same problem. I'm doing a topdown 2D game using 2D sprites with Animator for states. It works great but if I look closely, any position adjustments happen on a world axis and not local axis. For example, if the character is running on the Y axis then his head will move back and forth as he runs however if the character runs on the X axis then the head moves side to side. In other words, regardless of which direction the character runs, the head is moving on the world Y axis.

    I have parent objects and even parent objects for the parent objects and it still doesn't move on a local axis. I can work with it if it's a limitation but for me it seems ridiculous that such a simple thing is so uncontrollable (impossible to control with my current knowledge and I'm pretty good with Unity).

    I know if I'm doing animation on a normal 3D object then I'm sure there was properties in the animation window for local and world position. On the 2D sprite there is no mention of world/local, just "position" and it's non-specific in the description but the result is unfortunately ONLY world axis and it sucks.

    If anyone knows how to animate on a local axis I'd greatly appreciate knowing how to do it.

    PS. After looking at your setup, you need to make a gameObject for a pivot point and place the barrel as a child of that "pivot point game object". After you have done that, leave the pivot Point game object where it is and just move the barrel so it is in the position you want. Then when you animate, just rotate the pivot point game object on the axis that you need. To test which axis it is, just press play and test rotating the x,y,z so that you get the effect you want, then either code the animation or animate it so that it does it. I use this method all the time.

    Also, if your barrel is a 2D sprite, you need to go to the sprite editor and set the pivot point to the location you want it by clicking on the box that surrounds the barrel sprite then dragging the circle(pivot point of that box) to the position you want.
     
    Last edited: Nov 26, 2013
  3. Spielhaus

    Spielhaus

    Joined:
    Nov 27, 2013
    Posts:
    1
    Same problem here. How do other people work around it? There are tons of 2D games where animations would start at different positions and playing the clips would yield a visible offset/jump.
     
  4. Shinugami

    Shinugami

    Joined:
    Oct 17, 2012
    Posts:
    54
    I found the reason for it. When using Animator components, the animations played by the Animator component have a local axis to the gameObject which contains the Animator Component. My original problem was that the gameObject that contained my character did not rotate and so that's why it appeared to be animating on the world axis when it was actually animating on that container object's axis.

    For my game where i needed to use 2 Animator components (one for torso, one for legs) to make it so that the body animated correctly, it provided a new problem. I needed to sync the torso and leg animation and it was impossible to do as there is no way to get/set the progress of the Animator State.

    So I redid the code and am using 2D Toolkit which I bought a long time ago. The results are what I wanted to achieve but failed to achieve using Unity Pro features without 2DTK in that I can adjust animations without getting broken connections. I can still mix the 2D animation from unity with my hand drawn art and I can still use the Animator for unity animations.

    2DTK has a get frame function. I then use the 'PlayFromFrame' feature to sync my animations. I hope unity implements such a function for working with transitions which deal with animations of the same frame length.

    Update:
    Actually, I thought i had worked it out but further testing proved that even if I use 2 animator controllers, 1 of the controllers will work on local axis and the other will still resort to world axis.... Frustrating. I'll just leave out animations that can't be done by that method.
    Update 2: Because of the circular animation it was difficult to notice but it turned out all the animations are on world axis when it comes to transform.position :(
     
    Last edited: Dec 4, 2013
  5. Shinugami

    Shinugami

    Joined:
    Oct 17, 2012
    Posts:
    54
    Still no solution to this problem. I still can't animate a local axis with a .anim file. If the object doesn't move then there is no problem but if you are using a .anim file with a dynamically moving object then you have the barrier of the .anim using the world axis.

    Why can't unity staff solve this once and for all. Been like a year since I first encountered this and there are probably at least 10+ threads on the same issue and none of them are solved. There is always some madman rambling about how he solved it but fails to explain how he solved it.