Animating with Mecanim

0
timmypowergamer posted this 29 November 2015

Hi, thanks for this wonderful asset! I bought it in this weekends sale and I already see huge potential for it in my project.

One of the things I want to use it for is replacing my characters in my top-down shooter. I already have them set up to be controlled by Mecanim, and I was hoping to just replace their animations, but I see the way PicaVoxel does animation (at least the basic animator) is custom and separate from Unitys animation system.

I tried creating my animations anyway by key framing on and off the frames, but since they are all just named "frame", unity can't tell the difference between them. I'm wondering if you know of an easy way I could change it so that all of the frames get unique names (frame0, frame1, frame2, etc) and would it mess anything up too much if I did that?

I tried manually renaming them, which worked, but things got screwed up a bit when I tried to edit the frames afterward.

My plan is to write a tool that will generate animation clips for me just by specifying a range of frames, but I need some way of making sure every frame has a unique name (within the volume at least). Any insight or ideas you have would be appreciated.

Thanks!

Last edited 29 November 2015

7 Comments
Order By: Standard | Newest | Votes
0
GarethIW posted this 29 November 2015

Update: The code in this post is now included in PicaVoxel as of version 1.4.5

Hi!

As I don't get the chance to use Mecanim all that often in my projects, I haven't put much thought into how it might be used in PicaVoxel.

If you think that numbering the frames will help out with that, then that's a really simple change. Here's a new Volume.cs with frame numbering:

https://gist.github.com/GarethIW/90fc3d43c1249521cedf

Just replace PicaVoxel/Scripts/Volume.cs with that. If you have a current animation you're experimenting with, just move a frame left and right using the PicaVoxel animation tools and your frames will automatically be numbered.

Let me know if that helps with Mecanim integration. I don't know if it's possible to call a method on a target object in Mecanim, but if it is you can call Volume.SetFrame(frameNumber) to change the animation frame. I'm sure something like this must be possible, but my knowledge of the animation system is cursory at best.

Last edited 08 January 2016

0
timmypowergamer posted this 30 November 2015

Thank you! That works perfectly!

I am now working on an export script to generate the animation clips for me. When I'm done I'll post it here so anyone else who wants to can use it.

1
timmypowergamer posted this 03 December 2015

Well, as promised, here is my editor script for generating Unity AnimationClips for use in Mecanim: ExportAnimations.cs

To use it, just add the script to a GameObject with a Volume on it, fill out the info for each clip you want to create, and click the "ExportNow" checkbox. It will ask you for a folder to save them in, and if the clips already exist in that folder they will be updated instead of recreated.

When filling out the clip infos, the frames for the clip are specified as a comma-separated string. (ex. '1,3,5-10' would play frame 1, then 3, then 5 through 10, in that order). You can specify the frame rate for each clip, and choose whether it will loop or not. You can also always modify the clips manually after they have been created using the Animation window.

In my project, I used it to make a character with idle, walk, strafe left/right, jump, and attack animations, all using the same volume, controlled by Mecanim so there is not much code needed to manage it. I'm quite happy with how it turned out, but I may still be updating it and/or adding features as I go. Feel free to use it if you want to animate your voxel characters with Mecanim. If anyone has any questions or problems with it, let me know.

Edit: I should probably point out that this will only work with the frame numbering change posted above. Not sure if that's going to make it into the actual codebase or not.

Last edited 03 December 2015

0
GarethIW posted this 03 December 2015

That's brilliant! Thank you so much for sharing.

0
raveno00o posted this 08 January 2016

so i really like what is proposed above. but when i add the scripts it throws up a whole lot of errors :

Assets/PicaVoxel/PicaVoxel/Scripts/Frame.cs(80,30): error CS1061: Type PicaVoxel.Volume' does not contain a definition forChunkLayer' and no extension method ChunkLayer' of typePicaVoxel.Volume' could be found (are you missing a using directive or an assembly reference?)

Assets/PicaVoxel/PicaVoxel/Scripts/Frame.cs(363,82): error CS1061: Type PicaVoxel.Volume' does not contain a definition forPhysicMaterial' and no extension method PhysicMaterial' of typePicaVoxel.Volume' could be found (are you missing a using directive or an assembly reference?)

Assets/PicaVoxel/PicaVoxel/Scripts/Frame.cs(364,77): error CS1061: Type PicaVoxel.Volume' does not contain a definition forCollisionTrigger' and no extension method CollisionTrigger' of typePicaVoxel.Volume' could be found (are you missing a using directive or an assembly reference?)

Assets/PicaVoxel/PicaVoxel/Scripts/Frame.cs(571,55): error CS1061: Type PicaVoxel.Volume' does not contain a definition forChunkLayer' and no extension method ChunkLayer' of typePicaVoxel.Volume' could be found (are you missing a using directive or an assembly reference?)

Assets/PicaVoxel/PicaVoxel/Scripts/Frame.cs(576,96): error CS1061: Type PicaVoxel.Volume' does not contain a definition forCastShadows' and no extension method CastShadows' of typePicaVoxel.Volume' could be found (are you missing a using directive or an assembly reference?)

Assets/PicaVoxel/PicaVoxel/Scripts/Frame.cs(577,93): error CS1061: Type PicaVoxel.Volume' does not contain a definition forReceiveShadows' and no extension method ReceiveShadows' of typePicaVoxel.Volume' could be found (are you missing a using directive or an assembly reference?)

what im running: os:windows 7 unity ver:5.2.2f1 loaded assets:picavoxel,skybox5x

any help would be appreciated. thanks

0
GarethIW posted this 08 January 2016

The code I linked in the second post is for previous versions of PicaVoxel. The latest version of PicaVoxel (1.4.5) has the frame numbering built in, so you don't need to replace anything to use timmypowergamer's script.

I can't vouch for his code, however, but I had a skim through and I can't see anything incompatible with 1.4.5.

0
raveno00o posted this 08 January 2016

thanks very much! quick response. awesome.


Our 123 members have posted 452 times in 108 discussions