| Heli Merc: Enemies |
|
| Sunday, 28 November 2010 13:44 |
|
This time round I got stuck into the enemies, starting with designing a few low-poly models, including a jeep, a tank, an artillery piece with a few variations of each.
These are the brand new enemies, so fresh, that they haven't even had a coat of paint (texturing). I wanted to keep the polygon count as low as possible, so I've set a limit of 200 triangles per vehicle. So far, only the tank has come in under budget, and that's purely because it doesn't have wheels, so they'll need some more work before texturing starts. With some sample models done, I had to get them into Shiva, so I wrote a Python script for Blender that would extract each of the individual models into separate files which could then be converted to DAE using Blender 2.5. The reason for doing this is that I like to work on all the models in one file to keep them all a similar size, style and share the same material between them which makes them easier to import into Shiva. I could have left them as one large group and imported them into Shiva, but then I'd manually have to break them up into individual models, and since I'll be re-working these models several times over the course of this project, I'd like to automate the process as much as possible. Once the models were in, it was time to create a new AIModel to control enemies. This one is going to be a lot simpler than the sprite or weapon AIModels since I'm not going to use a pool of enemies. Instead I'll create the enemies at the start of the level. Of course, I may need to change a shared pool of enemies later depending on the resource requirements and how well it runs on the phone. Collision detectionThis proved to be pretty easy to set up, once I'd figured out how it works. I first had to make each of the enemy models a collider, which has to be done by opening up the models in the scene viewer and using the right mouse menu to set the object as a collider. Unfortunately, currently the only way to make a model a collider is to do it manually in Shiva, scripting can't do this. To improve performance, only the enemies were set as colliders. During the weapon update event where weapons are moved each frame, every visible weapon checks to see if it is colliding with anything by using the scene's getFirstHitCollider method and passing it a vector that is equal to the difference between the position of the weapon this frame, and where it will be during the next frame. The result from this provides sufficient information to work out the collision position (if one occurs) with pixel perfect accuracy. When a collision happen, the weapon is replaced with a small explosion as it normally is, and the vehicle's hit points are reduced. When the hit points reach zero, the vehicle is replaced with an explosion. Using the getFirstCollider with a movement vector is a good way of avoiding fast moving weapons appearing to "pass through" enemies between frames. Sound effectsI added in an explosion sound so that the missiles and vehicles made a noise when they exploded, and in doing so, found out about a minor Shiva quirk. Each object is assigned a "Sound Bank" which is a collection of sounds that the object can play. It turns out that although a single object can play multiple sounds at once, it can only ever play a single instance of each sound that is in the bank. For instance, if a missile explodes, and I decide I want to play the "boom" noise twice, I can't simply call the play method of the sound class twice or the second call gets ignored because the sound is already playing.To be able to play the same sound effect twice at the same time, two (or more) instances of the sound effect need to be assigned to the bank, and both need to be called separately. Try out the latest version discussed in this blog post! Return to the Heli Merc section! blog comments powered by Disqus |

