Thursday, November 25, 2010

A Belated Beginning

So, naturally I start writing a development diary two thirds the way through a project.
Rather than ramble on about this and provide such uninteresting things like "reasons" and "excuses" I'll cut to the chase and start recapping the last few weeks of work.

So here's that chase I was talking about.

The Grand Idea
There's not a whole lot to explain here, the whole theme of monkeys and Morris Minors was born out a need to come up with an idea within a self-imposed time frame of roughly five seconds.  Regardless of the irresponsible choice to not think things through, it gave me a neatly formed sandpit to start playing around in.  A sandpit containing monkeys and toy cars.

So far any gameplay mechanics haven't been worked out, but my reasoning is sound.  Firstly, the project is centred around the visuals and intelligent use of assets.  Secondly I wanted to get a vehicle working first.  Then test out it's capabilities and see how far I could tune the control of said vehicle without too much heavy lifting (scripting).

As for that vehicle...
That Vehicle
Urgh.  This was an absolute nightmare.  The sort of nightmare that involves starting at UnrealScript for hours on end.

However it all started off with nothing more than a bunch of pretty pictures of Morris Minors in various configurations, a bit like this:
















Yes, they're all very lovely and some even verge on awesome... However I wanted to start off with just your bog-standard Morris Minor and work from there.
(Note...  Looking at this again has reminded me that I completely forgot to place a grill on the from of my Morris.  Crap.)

After finding some decent reference material I entered a fairly painless modelling process and came up with this resulting model that's lacking a grill:
Rather conveniently some of the shapes of the Morris were close enough to those of a vehicle modelled for an earlier project, namely the front wheel arches, wheels, wing mirrors and the bumpers.  The inside parts were also scavenged from a set of reusable pieces of geometry made for the same project.  Helpfully, I had already UVd them so this saved me a considerably small amount of time for which I am grateful.
This has given me cause to create a larger gallery of reusable assets like this, maybe even a MEL script to access them.  Headaches are on the horizon!

Texturing was a simple job consisting of an AO bake, flat body colours and a specular map, however this gets considerably (debatable) more exciting a bit further on into the UDK side of things.  Promise.

Now, this is where the painful stories begin.  So if you're afflicted with a weak heart, short attention span or apathy you should probably stop reading now and jump forward to a part that has pretty pictures. 

The next stage here is the whole rig n' import process.  My initial way of going about this was to replace the material and mesh assets for the existing Scorpion vehicle.  It seemed to work for a couple of others on my course...  So it must work for me, right?

In a word, no.

Rigging the Morris with an identical skeleton to the Scorpion with all bones and names present, then overwriting the existing skeletal mesh should have worked, but it didn't.  It may have had something to do with the fact that I renamed the Scorpion's assets to back them up, and UDK kindly changes all the internal references to that object for you.
So no matter what I called the Morris mesh, it still used the Scorpion mesh.
There was some small "success" in importing the Morris' blend shapes.  Success in the fact that that they worked.  Failure in the fact that I completely broke the Scorpion's Morph Targets.  However I did end up creating a Mighty Morphing Morris Minor.
After an awful lot of back and forward between UDK and Maya I came to the conclusion that what I probably should be doing is creating the Morris as it's own vehicle.

After scouring the internet for tutorials and information, the creation of the Morris Minor as it's very own being began.

The first port of call was to reduce the skeleton to just the bones and joints needed then reskin it.
The joints used are the root (obviously), four wheel joints, four axle joints and a joint for the boot.
Then import mesh, Morph Targets, textures back into UDK into a shiny new VH_MorrisMinor package, put them together and you have yourself a lovely skeletal mesh that functions perfectly as a skeletal mesh that does nothing else.

Before I move onto UnrealScript hell, here's those Morph Targets in action.  Well, not really in action as that would require video.  Expect that at a later point.

After carefully reading through tutorials on how to create a custom vehicle, and coming across some UnrealScript based on the Scorpion, but with all Scorpion-specific funtionality removed, work commenced.

Modifying the scripts to work with the Morris was relatively simple, mostly a case of renaming any references to the Humvee from the tutorial script to VH_MorrisMinor, then making sure the script VH_MorrisMinor_Content was pointing to the vehicle assets:

A couple of changes to the SkeletalMesh reference in a couple of other scripts and class path updates and everything looked set to go, aside from a small snag with a couple of lines of code causing the compile to fail.  Props to this guy for running into the problem before me and finding a solution.

Everything worked, the code compiled without, I could place the vehicle in the editor, I could hit Play from Here and.... Crash.

Oh.

Try again...  Crash.
Back I go to the script, check over everything... All the naming, references, classes I renamed...  Compared it to both the Humvee script and the unedited Scorpion script.  Adjusted and experimenting with anything that seemed off and still no success.  
After two hours of this I decided to give up and go back to building the map itself and test with the Scorpion instead.  Only in the process of attempting to alter the Scorpion assets it had become completely broken and wouldn't spawn at all.  Eventually the Manta hover-vehicle had to come in as a less than ideal solution for testing.

A couple of days later I deemed it time to have another stab at getting the Morris to work again.  After an optimistic attempt at putting it in the map and hoping everything had fixed itself... Nothing.  Crash.  Not in the spectacular vehicular way.

A sudden thought came across me...  Crash logs!  After digging them out, a clue was found:
There would have been a picture of the crashlog here, but it's since been overwritten.  However the clue was along the lines of this: 
Function Engine.SVehicle:PostInitAnimTree:0075
The internet failed to find me a solution, as all I came across was a lot of people having the problem, but no-one giving any answers.  So I took it upon myself to investigate.  First by scrutinising the AnimTree for the Morris, comparing the naming to the script, but everything was fine there.  Then by analysing the SVehicle script and finding out about PostInitAnimTree...  Not a lot of useful information.  The best answer I came across was that the script couldn't find the Morris' wheels because they weren't named properly.  Yet they were.
After several hours over several days attempting to fix the problem and failing I decided to leave it until I could consult ARU's resident UDK expert Hywel.
It took us an hour.  Hywel eventually noticed that that the scripts were from different UDK versions, which led to us both sitting there comparing my Morris code to the up-to-date Scorpion code for any differences.

And there it was.

One line right at the top of UTVehicle_MorrisMinorWheel.  An 18-line piece of script:
class UTVehicle_MorrisMinorWheel extends UTVehicleWheel;
Which should have read:
class UTVehicle_MorrisMinorWheel extends UDKVehicleWheel;
Changing that one line fixed (almost) everything.  The vehicle spawned but wouldn't drive.  fixing it was simply a case of changing the UTVehicleSimCar class to UDKVehicleSimCar and hey presto!
This:


That's a lot for one post.  I'll write about the approach to the visual design, material set ups and modelling other assets and tuning the Morris in future posts.
For now, rest assured the somewhere right now a virtual Morris Minor is crashing into bad geometry.