Search

Bumping Into Things: Modeling and Materials (Part I)

Updated: Aug 22, 2019

I am not an artist; you should just trust me on that. Since Alien Cow Farm is still a solo project (for now), the original plan for all of the assets was to create them in-Unity, using the default sphere, cube, plane, and cylinder primitives. I truly felt that this was a reasonable goal for the simplistic, cartoony style I wanted. But two problems quickly arose: colliders and textures.


A collider is a component placed on a gameObject to allow it to interact with other objects in the game, either by obeying the physics of the collision or just registering the event and taking other action. Unity includes a set of primitive colliders as well, but they aren't without their own problems. First, for whatever maddening reason, there isn't one for the cylinder. Second, the one for the sphere does not deform into a non-sphere if you non-uniformly scale the object it was created on, like the box collider automatically will. I.e., you can have an ovular object but a perfectly spherical collider is the best you can do. This can be a problem if you need really accurate collisions in your game.


In my previous projects like S.P.A.R.K. and Trials of the Rift, 3D games with complicatedly-shaped player characters, we'd been able to generate mesh colliders on importing those models. A mesh collider is one that fits its model perfectly, and while it can be expensive to calculate collisions for, you typically won't notice any problems if you just limit its use to the player and use primitive colliders for everything else. The ultimate problem, though, is that you need a mesh to generate the mesh collider off of; a single, solid mesh, not a bunch of primitives cobbled together.


I tried combining mesh colliders with the compound colliders method to better approximate my objects. Basically, you use a bunch of smaller colliders to cover different parts of the model for a more accurate silhouette in the end. I put individual colliders on each of my spaceship's components, with a mesh collider being used for the ring instead of the too-big unscaled sphere...but then I started getting double the collision events if more than one of those colliders was triggered. There are other tricks to get around this kind of thing, but suddenly the simplicity I thought I'd achieved by doing all my modeling in-Unity was being wasted on hacky workarounds.


I figured that the solution was to follow the previous workflows to the letter. If I could import a UFO model as a single mesh and generate a mesh collider from that, I'd solve all of my collider problems at once. For my external modeling needs, I turned to blender. Not because I was already familiar with it or because it was easy to use (because...uhh…), but because Maya, the industry standard I was taught in school, is not open-source and I wouldn't legally be able to make any profits from my game without buying a pricy license first. blender is about the most backwards piece of software I've ever used, but I followed enough tutorials to be able to recreate my three-shape UFO there and get it back into Unity (and let me tell you...there are a lot of tutorials dealing with the how to set settings and adjust the scale and rotation for export/import between the two programs alone).

My UFO recreated in blender

So, I bring the model into Unity, click to generate mesh colliders...and receive an error that I can't, because my mesh is too complex. Seriously? That little thing? If Unity can't handle that, what the hell good are mesh colliders anyway? (Apparently, they are good for dropping onto static objects, like the entire level floorplan your modeler has created and the programmer doesn't want to spend time adding box colliders to every floor and wall.) Before giving up, I made one last attempt: I created a very simple cylinder object in blender, then exported and made a mesh collider from that. It worked, so now I have my own primitive cylinder collider that I can use on any model I like. And to be honest, that's all I even wanted from the beginning, if only Unity had provided one of their own...

Mesh collider shown in green

This gave me the accuracy that I needed with a single collider.


Next time: Part II, texturing and materials!