Train Defense 2‎ > ‎

Train Path

posted Jul 11, 2012, 10:14 AM by James Podesta   [ updated Jul 12, 2012, 8:37 PM ]
Tonight I ported the train path code. It went over surprisingly smoothly. I was expecting some issues since all my maths are in radians, but many of Unity's maths use degrees interfaces, and since they are both floats, its easy to mix them up.

While the code ported easily, it actually took me an hour to get the path onscreen. Using Debug.LineRender I could see the path was being created correctly, but nothing would render.  Turned out that I forgot to give the path mesh triangle indices. The original code was a long triangle strip, which is more optimal and doesn't need indices, but I need Pro version of unity to access strip rendering functions in there Open GL module.  I haven't ran this latest build on iOS yet to see how the performance is hit by Unities dynamic mesh system. Fingers crossed it is fast, or else I'll need Unity Pro to fix it.

Once the path was in I ported the train movement code across. I hit a brick wall trying to get the train wobble to work. Unity transform doesn't allow any direct control over the transformation matrix, so its not possible to do the skewing I was using.  Shaders to the rescue here - I made a quick outline shader that takes a pre-transform matrix. Its a bit of a painful solution, since its added expense to the shader, plus I'll have to make sure to apply that matrix to any attach points for attaching turrets to the train,  but overall its not a big issue and some of the maths are simpler this way.

I added in a few enemy templates and made them home in on the player. you can use the mouse to drag out a path. its not final UI code since you can currently just click anywhere to make a path, which is wrong.



Train Defense 2 - Prototype 004



Comments