Search Unity

Smooth Moves - 2D Skeletal Animation

Discussion in 'Assets and Asset Store' started by echo17, Feb 20, 2012.

  1. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I'm not an animator by any means so I can't say what the "best" method would be. You could certainly hide the head and create a separate head object that appears and rolls around. You could also just animate the head falling off (assuming your head is a separate bone) in an animation clip. I would try the animation of the head coming off myself, but you'd get the same animation everytime the head comes off. You could also create multiple beheading clips to get some variety.

    Pretty much the same answer as above. It really just depends on your style. As far as technical solutions go, Smooth Moves does not have a ragdoll function built in, but you may be able to attach a ragdoll if that's what you want. Again, with 2D animations, it might just look better to do the animation without any physics.
     
  2. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    The problem, is that the head needs to roll, bounce, around the scene.
    For example, if the character is flying with the jetpack, and get a head shot, the heads will get flying away, hit the ground and bounce. To this, I would need physics.
    The same to the rest of the body, if he dies in the air, I wanna make the parts of body fall arround.

    The idea, is, that without head, you start losing health fast, and, if you dont get back your head, you will bleed until death. But, if you get the head back, you stop bleeding.
    The body parts falling around is only for fun, nothing that changes gameplay. Then, can be ignored for now.

    Thinking on your reply, I think that I will hide the head, and create a new object with the head sprite.
     
  3. EnigmaFactory

    EnigmaFactory

    Joined:
    Dec 10, 2011
    Posts:
    98
    I haven't got to play it yet as I am work, but that sounds like an awesome gameplay idea! I really like it.

    To answer your question, I'd just hide the head bone and spawn a head object in the proper place and apply physics. If you want more control over the beheading, then animate it popping off and hid it then spawn the head object.
     
  4. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Mixing layers is awesome, then I can mix the beheading animations. Very good idea boys, thanks.

    Another thing, my Y Axis, will define the aim of the weapon, then, how I can do, to rotate the weapon around 60 degrees?

    I need to create an animation to each position of the weapon, or can do something more precise?
     
  5. jgodfrey

    jgodfrey

    Joined:
    Nov 14, 2009
    Posts:
    564
    You'd probably just want to rotate (in code) the bone that controls the weapon, based on some appropriate User input.

    Jeff
     
  6. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Exactly, but how to do that?
    I can add a bone that can control all the weapon and arms, and then rotate. But how?
     
  7. Mark_VX

    Mark_VX

    Joined:
    May 22, 2011
    Posts:
    2
    Hey there echo17,

    first off: Awesome work mate! You've easily shaved off a month+ of my development time ;)

    I was hoping you might be able to add this little tidbit in an update:
    As far as I can see the rotation is only possible on a single axis, would it be possible for you to add the other two as well?
    (I'm guessing you've actually excluded them on purpose).
    As they would help in creating the illusion of foreshortening if utilized correctly!
     
  8. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    Just bought it, removes a lot of tedious work - which for me means the difference between actually getting work done and putting it off til later (never).

    Haven't delved too deep, but I second the request for other axis rotation, if possible. I know it's not going to be needed most of the time, but I was using it to animate some bee wings in my manual make-a-bunch-of-planes-in-Blender method. I figure I can fake it with some scaling, but..
     
  9. sanjodev

    sanjodev

    Joined:
    May 29, 2012
    Posts:
    63
    Quick question. I see how you register for collider events and user trigger events with the BoneAnimation object. How do you register for a event when a particular animation completes?
     
  10. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    my looped bone animation is continuous on smooth moves animation editor. when i play this animation on my game it waits few frames to start again? it is 15 frames length animation. on game it behaves like it is 25 frames length animation and it adds 10 empty frames.in editor it is the last keyframe on 15.

    i could not find what i did wrong
     
  11. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    You'll need to be sure you have no animation curves on the bone that you want control manually. For this bone, you'll only want the first keyframe set. you'll get the warning icons, but in this case that is a good thing. When there is only a single keyframe, the animation curve will not be created and Unity's animation will not override your own settings.
     
  12. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I'd thought about it, but since the editor uses Unity's GUI to render the preview, it isn't possible to show the rotation along the x or y axis. It would work in the scene, but not having an accurate preview would be confusing. I'll keep it in mind in case there is some way to get around the GUI limitations.

    Thanks!

    [EDIT] You could try faking the rotation on the x and y axis by scaling on these axis. I know it's not as intuitive as just rotating, but it may get you close to what you want.
    [/EDIT]
     
  13. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I would put a user trigger on the last keyframe of an animation. That would fire when the animation is complete (if your wrap mode is set to once or clamp, otherwise it will keep firing).
     
  14. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Hi atmuc,

    Can you send me your project to support@echo17.com? I'll have to take a look at the animation to see what is happening.
     
  15. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    Code (csharp):
    1.     public BoneAnimation fish;
    2.    
    3.     // Use this for initialization
    4.     void Start ()
    5.     {
    6.         var newFish = (BoneAnimation) Instantiate (fish, new Vector3 (0, 0, 0), Quaternion.identity);
    7.        
    8.     }
    i try to instantiate new prefab with this code. i get this error. how can i create new bone animation prefab?

    Quaternion To Matrix conversion failed because input Quaternion is invalid {nan, nan, nan, nan} l=nan
     
  16. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    This looks like there is something wrong with one of the animation's rotation curves since that is where the quaternions are used. Be sure you are on the latest version of Smooth Moves (1.9.5). I seem to recall that this was a bug that was fixed in a recent version.

    If you still have problems after upgrading, you can send me your project to me support email and I'll have a look.
     
  17. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Right, but how I will program to rotate a bone?
    Can you explain me? Show some code?
     
  18. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Sorry, I misunderstood the question. You could do something like this:

    Code (csharp):
    1.     private Transform _headTransform;
    2.    
    3.     public SmoothMoves.BoneAnimation boneAnimation;
    4.    
    5.     // Use this for initialization
    6.     void Start () {
    7.         _headTransform = boneAnimation.GetBoneTransform("Head");
    8.     }
    9.    
    10.     // Update is called once per frame
    11.     void Update () {
    12.         if (Input.GetKeyDown(KeyCode.Alpha1))
    13.         {
    14.             _headTransform.localEulerAngles = new Vector3(0, 0, 30.0f);
    15.         }
    16.         if (Input.GetKeyDown(KeyCode.Alpha2))
    17.         {
    18.             _headTransform.localEulerAngles = new Vector3(0, 0, -30.0f);
    19.         }
    20.     }
    Pressing "1" will rotate the head to 30 degrees. Pressing "2" will rotate the head to -30 degrees.

    For this to work, the head rotation cannot have more than one key. I've removed the second head rotation key from the stand animation of the knight like this:

     
  19. sanjodev

    sanjodev

    Joined:
    May 29, 2012
    Posts:
    63
    I was hoping not to have to do this and if there was a better solution. If this is the best way, then oh well.
     
  20. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Sorry, Unity has no signal to let you know that an animation has completed, and in the case of a clamp it will never actually complete. Setting up the user trigger gives you full control over when you are notified of any frame being reached. A little extra work, but much more efficient than having to constantly check if an animation is running every frame.
     
  21. pushbyte

    pushbyte

    Joined:
    Apr 1, 2012
    Posts:
    9
    I just picked up Smooth Moves because it looks perfect for a project I'm working on. Kudos to you for releasing such a nice product, echo17. :) I haven't had a chance to play around with it yet, but can anyone tell me if Smooth Moves alone is enough to complete a simple 2D game? Or will I need to use it in conjunction with another 2D package (ex2D, 2D Toolkit) for the backgrounds, collisions, etc? Sorry if this has been asked before.
     
  22. EnigmaFactory

    EnigmaFactory

    Joined:
    Dec 10, 2011
    Posts:
    98
    What about using isPlaying? Could set a flag variable once isPlaying equates to true and when it becomes false change the flag variable. User event is probably the best method, but this may work depending on implementation.
     
  23. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    my both problems were because of there was single keypoint on children of my root bone. i duplicated first frame to the last frame it is ok now
     
  24. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    how can i mirror images? for example on knight example i want to turn knight to left when i press left cursor.i dont want to add another image to the atlas.
     
  25. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I would recommend using it in conjunction with other 2D tools. Smooth Moves focuses primarily on the character bone animation, pretty much replacing the need to create models in Maya, 3DS, blender, etc. For sprites and GUI, I'd recommend going with a package tailored specifically for those needs like 2D toolkit and NGUI, respectively. I do have sprites in Smooth Moves, but they are not as fleshed out as these other two packages that tailor specifically to this need.
     
  26. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    You could do this, but as I mentioned in my post this would not be efficient since you are polling the state every frame. Also it would not work for looping animations using the loop or ping pong mode. It would also not work for the clamp mode since the animation just repeats the last frame over and over and never stops. So this would only work for the once wrap mode.

    By setting a user trigger you are guaranteed to fire that frame every time it hits it, whether the animation is looping or not. Plus you only have the overhead for that one frame and not every frame.
     
    Last edited: Jun 19, 2012
  27. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    There's a couple of ways to do this:

    1) Rotate on the Y axis 180 degrees
    2) Scale the x axis -1.0f

    Smooth Moves will correctly draw your animation backward because the depth will determine the order of quads facing both directions.
     
  28. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    on each update i increase the x position of an bone animation object. how can i detect that the object is out of screen?when it is out of the screen, i want to set its position to the left of screen. anchor is at center so i must get the width of the bone animation object,
     
  29. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    it worked :) so, animation bone is like an unity game object and we can apply nearly everything that we use with unity game objects.
     
  30. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    That really depends on your implementation of the game. You could check the character's x position to see if it is beyond a certain value, or you could go the more expensive route and cast rays at the character to see if it is still onscreen. There are probably better methods than these; I'd suggest doing a search in this forum for how to tell if a character is still on screen.
     
  31. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    BoneAnimation is MonoBehaviour. I can instantiate it in my script. Instantiate method returns BoneAnimation object. i set it as a prefab. i added a script to this prefab. in this script i want to get the owner(BoneAnimation) reference. gameObject property is Unity GameObject. how can i get BoneAnimation reference?
     
  32. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    You could do something like:

    Code (csharp):
    1.  
    2.  
    3. void Start()
    4. {
    5.     SmoothMoves.BoneAnimation boneAnimation = gameObject.GetComponent<SmoothMoves.BoneAnimation>();
    6. }
    7.  
    8.  
    9.  
    I'd suggest reading through the Unity manual and reference, or searching through the forum. There's a lot of useful tips like this that aren't directly related to SmoothMoves but come in handy for all project types.
     
  33. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    i set pivot point of an image on atlas. it is on up-center. i added a bone of this image.i set box collider and clicked Match Texture Size. it makes box collider centered to pivot point. i want collider to be on center of this image.is there any easy way to set it to center?i dont want to set it from coolider center xyz boxes.at least can i drag to move collider box?
     
  34. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    I have 5 frame bone animation.first and the last keyframes are the same. at the first frame i select root bone box. i edit local position. i play animation on smoothmoves animation editor. there is no movement there as expected.i generate bone animation game object.i select my bone animation.i play the game.my bone animation object moves for 5 frames. it is like root has keyframe at the last frame. is it normal?

    also when i click animation data on bone animation script in the list i cannot see my bone animation objects. i have to drag/drop my bone animation from project window. is it how it works?
     
  35. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Sorry, the only way to set the center of a collider is using the collider center input textboxes.
     
  36. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Be sure you have at least two keyframes for any of the following properties:

    1) Local Position
    2) Local Rotation
    3) Local Scale
    4) Image Scale

    Without two keyframe, Smooth Moves will not generate an animation curve. This is the reason I put in warnings on bones that have on a single keyframe for any property.

    Not having two keyframes is good if you want to animate a property in code, like making a bone following something else, for example.

    I'm not sure why Unity would not show the animation assets. Yes, I guess you'll just need to drag the animation data asset to the bone animation script.
     
  37. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    i made an bone animation object and i created prefab from it. i generate game objects by instantiating this prefab. when i change bone animation like collider it doesnt update prefab even i choose "update all bone animation in scene". how can i update prefab automatically? i dont want to delete and recreate prefab everytime.
     
  38. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Be sure you are on the latest version. Earlier versions did not automatically update the collider. The animation will update itself when you press play.
     
  39. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    it updates all objects on hierarchy. i mean prefabs on the project window not on the hierarchy window. they are not on the scene at start. later i instantiate them in my c# scripts. your update is on design time and does not effect prefabs.
     
  40. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    i had my bones and i added a bone and set it as "Make Bone the Base" the i decided to delete this bone. deleting this bone deleted everything.i did "undo boneanimation data" several times. i lost everything on this bone animation data. :-(

    what is the way to delete base bone?
     
    Last edited: Jun 24, 2012
  41. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I see what you are saying. The prefabs will regenerate the mesh and animation data at runtime. I will look into a way to update the prefabs in the project at design time.
     
  42. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Undo should have reverted back to a previous state. Be sure you use ctrl+z and not unity's undo menu. It doesn't hook in for some reason.

    The best way to delete a parent bone and preserve its children is to move the children to another parent first, then delete the bone.
     
  43. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    I used both for undo. i will use ctrl+z.

    my bones are A->B (a is parent) then i created new one as C.then i set C as base C->A->B. what is the way to have again A->B without using undo?
     
  44. Sytto

    Sytto

    Joined:
    Jul 20, 2010
    Posts:
    28
    Hi, i just bought Smooth Moves and its perfect and best for me, but I have a question, my character has a set of wearable objects and when i flip it (changing X scale to -1.0) items go behind it.

    Is there some function or code for fix it? thanks and sorry for the noob question


    edit: it's fixed using Smooth Moves sprite instead of using a normal cube lol, sorry for the dumb question
     
    Last edited: Jun 24, 2012
  45. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I would just drag A to the root
     
  46. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    No prob. You could also rotate 180 degrees on y axis
     
  47. Sytto

    Sytto

    Joined:
    Jul 20, 2010
    Posts:
    28
    how I can set any texture of my atlas in any bone of all animation clips and keyframes without using this way
    http://www.youtube.com/watch?v=MZ8ICqIh0Mo

    I made my own function but doesn't work because not all frames of some animation clips have keyframes so when I use

    SetAnimationBoneFrameTexture function at certain frame without keyframe it throws nullreference and stop working
     
  48. robin_notts

    robin_notts

    Joined:
    Apr 7, 2010
    Posts:
    86
    Can I make a tiny request? Can the animation window (and possibly the atlas window) show the animation name in the title bar? Sometimes I forget which file/version I'm editing and can only make sure it's the right one by closing the window and re-opening the animation.
     
  49. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    SetAnimationBoneFrameTexture just sets the texture on a single frame, bone, animation clip. If you want to replace the texture on all keyframes, you can use:

    ReplaceBoneTexture (for all animation clips)
    ReplaceAnimationBoneTexture (for just one animation clip).
     
  50. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Sound reasonable for the animation editor. I wouldn't do it for the atlas editor, though, since the atlas could be used in different animations. I'll add this to my list.