Thursday, June 30, 2011

Eyegore - Post Mortem

So it's all done and we've said our goodbyes, but on the off chance that some of the later GDs read this, here are some things were learned along the way that might help you.

Things to Know About Unity if You Don't Have a Programmer
I was the programmer, but I am not a programmer. I learned tons and it was an awesome experience, but there were some hard Unity lessons along the way. Learn from our pain.

1) Always check your animation frame rate. We discovered that Maya was set to 24 FPS and Unity was set to 30 FPS for animation. When you import a 24fps animation into Unity, it pads the frame count to make it 30fps, leaving all your animator's frame numbers useless. Always ensure frame rates are proper in your animation program before exporting.

2) Keep consistent pivot points. You can center the pivots in Unity, but the only ones that matter are the local ones on the object. We had issues where I was destroying and instantiating objects and the instantiated platform was way off position because the pivots were in a different place.

3) Prefabs are awesome! Prefabs allow you to make a prop, platform, enemy and so on and drop them into a scene. If you make a change to one copy of the prefab and apply it, all copies take on the same properties. It's a lot easier than finding 200 individual items in a scene and manually changing them. By the time the end of the project rolled around and the levels were getting dressed up, the prefab thing was not followed. It was ugly and wasted a lot of time.

4) Create prefabs on empty game objects. I learned this early on. For example, I created Eyegore using the animation as the base of the prefab. When we changed the animations and I had to re-import that model, I ended up having to redo all the program links, triggers, colliders, lights, effects and a bunch of other stuff. Creating a prefab on an empty object makes animation or other components just a module you swap out and is very useful.

5) In your hierarchy view you can drop an empty game object into it and use it like a folder. For example, and empty game object labelled 'Walls'. Then in hierarchy you can drag all your in-scene walls into that game object and massively reduce clutter. These may not transfer between builds... at least my team swears they were using them when I turned around enraged at the spaghetti in my hierarchy folder.

6) Animation events are awesome. The documentation for them is great except for one little note. If you have not created the animation in Unity and instead have imported it, animations are read-only. Go into your animated object, and duplicate the animation. I made a folder called 'Edited Anims' and drop it in there with a name like WalkEdit. Replace it in the object's properties. Now you can edit the animation in the event editor.

7) Use colliders instead of triggers where possible. Holy cow, this caused so many spawning issues for us. If your character dies when he hits a trigger, welcome to 300 respawns! Where you need to use a trigger, Mat showed us an awesome couple lines of code that will prevent a character from respawning in the same frame (and can easily be adapted for a longer time scale).

8) Unity's collision can be a little fussy at times. I was experimenting near the end with discrete vs interpolated collision but didn't come up with a definitive answer on the way to go before we finalled. We ended up burying triggers in the middle of solid volumes because having the character fall would often hit triggers a full body width away due to interpolation.

9) Never use cloth physics if you want to pause the game. Cloth plus time.scale = divide by zero. It will kill your game.

10) Sound is fun! It defaults to logarithmic drop off. We did not know that. I had the listener on the main character and the source on the camera. They were too far away and you could barely hear the sound. Log dropoff is really best for localized, repetitive sounds (like the constant crush of a cycling trap, or a local siren). Use linear for sounds you want to hear anywhere or that are one offs (main character noises).

11) Along the same theme, if the sound if still distorted or has strange volume issues, switch it from 3d to 2d. It will clear right up in many cases.

12) Fun fact: if you're doing a side-scroller, a cube collider will act with some weird drag and push the character off the axis. We used a capsule collider and a z-lock script for movement to keep him on track. This also happens to things pushed or pulled along the axis. A quick script will lock them in place. Just make sure your levels are built along the same axis or he'll be free falling.

13) Particle effects are very cool. Unity standard comes with a number of very neat ones that can be updated and changed for your project so you don't have to start from scratch if all you want is a flame or explosion.

14) 'While' loops are bad. Very bad. Worse than cloth/Time.scale bad. It's divide by zero then divided again by zero bad. Anything in an Update function acts like a 'while' statement. So, no while statements, mmm'kay?

15) Don't worry if your code is ugly, as long as it works. By the time the last build rolled around, I was a little embarrassed by my earlier code. It was clunky and there was more efficient ways to do it. However, it worked. I'd rather have ugly and effective than sleek and non-functional. Just get used to saying 'Yeah, I know" with a shamed grin when a real programmer reads your code and gives you a disappointed look.


Good luck and have fun!

1 comment: