So 2 major additions.
Probably hard to see in a window this size, but the train happily bobs around as it moves now. This was trickier than expected since it requires a simple shearing of the transform matrix, but Unity's transform system does not support this. The only transforms you can do are scaling, rotation and translating. To achieve it I've had to modify the vertex shader to accept a custom transform that is applied in local space before passing the vertice on to the rest of the pipeline.
The more significant addition is adding attachments system. I couldn't just add child objects because of the skewing animation I mentioned above - Unity doesn't support skewing of the hierachy. So I've had to add my own custom attachment components. Its actually a fairly simple system and gives me more control over special cases and update ordering, so I think its for the best.
The attachment system is done by having an AttachList component which you add to the parent object. It lists what prefabs to instantiate and what attach point to attach them to. Each model can have any number of named attach points.
The child object is given a script derived off an Attachable component. The Attachlist component calls an update method in the attachable component each frame during the parents LateUpdate. Thus all attachables update after all parent objects. There's not much more too it. The Attachable update knows the attach points and parents objectToWorld transform, so can position itself how it wants.
Currently I just have a 'peashooter' attachable, which is a basic single turret gun that aims at any nearby enemies. I don't have a projectile system yet, so I can't actually shoot anything, so that's what I'll be implementing next.
Finally, I thought I'd have fun with some timelapse desktop capture software I downloaded - chronolapse -which makes it so easy to record a PIP timelapse of code & webcam. So tonights blog includes a small timelapse of me implementing the attachment system.
Train Defense 2 >