Monday, September 30, 2013

Update 21: Alpha 1.57 - Upgrading the character model

With the timing fixed, it was time to take the next step in implementing line of sight. 

An early line of sight mechanic highlighted how simple my character models were. As my characters are still just a single object (cylinder), cover effectively made my targets invisible if the one point of balance in the center of the cylinder was behind cover. It was time for me to develop my characters a little, to have multiple points (head, arms, body, etc).

Heading to my sketchpad again, I tried to design a simple model about the height and width, with arms, legs, a body and head.





The new model ends up looking a bit like this (with the old model to the left). It's a little silly looking, but is enough of a person for me to continue building the game engine.


What does he look like in a level? This is some basic animation I am using to aim at a target (The right arm is at 90 degrees - like I said "BASIC"). There is still a long way to go, but this is at least an upgrade from the cylinder.



Friday, September 27, 2013

Update 20: Alpha 1.56 - Timing

One of the biggest bugs in my code has been the timing of the camera movement, shooting and throwing. I've put off solving these problems for a variety of reasons, but with some early AI experiments, I found that it suddenly became essential to solve this immediately.

Fundamentally, the issues come from my usage of Coroutines, a Unity function that runs until it is finished. It's almost the same as creating a new thread. I use coroutines for my camera movement, shooting, throwing, and soon, for AI.

My game is simple, but still complex enough that I decided to create a separate  isolated test level to solve this problem. This little doodle shows my plan. I need two 'paddles', a ball to bounce back and forth, and the camera to switch between the two paddles between bounces. This functionality is all very similar to the way my camera follows a character taking their turn, and has them shoot/throw an object at an enemy.



With this design, my test looks like this:


I was able to easily try a few different tests, running through the 5 steps designed above, firing two projectiles instead of one, and really ensuring that the timing was working. I found that I could never get coroutines to wait. My bug was relatively simple (of course), and I've spent the last few hours actually refactoring the main branch of the code. Once this is working, I'll post about the AI.

Friday, September 20, 2013

Update 19: Alpha 1.55 - Targeting and More Dynamic Explosions

Continuing with my momentum, I've implemented a new mechanic based on some feedback I received. When the camera zooms in behind a player to shoot, it now shows a partially-transparent-targeting-indicator. It's now a little more obvious who you are aiming at, especially when there are a cluster of enemies close together.




I've also been working at creating more dynamic explosions. In Version 1.45 I had created a prefab that contained little blocks. When the prefab was hit, I'd basically pull down the wall and let the little blocks explode. While effective, I found that when I scaled up from a 10x10 level to a larger 30x30 tile level, that the prefabs and all those little blocks really hit the frame rate pretty hard. 

To solve this, I wrote a little class that divides the parent object into a series of smaller cubes - created when I need them. Then instead of a million little cubes buried in my level, the cubes aren't created until they are needed.

Here is a sample before:



And after: 





Next on the list is some timing and camera improvements.



Tuesday, September 17, 2013

Update 18: Alpha 1.5 - Finally Moving...

I finally have my characters moving. If you know me and have talked to me about this project, this has been a significant barrier for the duration of the project to date. I've tried multiple path finding algorithms and methods to move my characters, mostly with pretty horrific (lack of) results.

Today that changed. 

It's simple, but it involves two pretty important mechanics. 
  1. A simple tile based system that highlights possible moves. This creates the 'sectors' my game needs, but still gives me the flexibility to not be tied to these tiles. 
  2. The ability for me to click on the highlighted tile and actually move the current character to that position.
The test level below shows both mechanics at work, but in the final game, the red grid will not be visible.




You can download the Alpha 1.5 version here: http://www.samsmithnz.com/content/tbe/tbe_alpha1.5.zip. Also included in this build are links to some of my test levels, where I develop and validate mechanics in isolation, the explosions from 1.45 and some more bug fixes. 



As well as this, I'm still continuing to improve dynamically exploding walls, setting up the final milestones for the complete Alpha demo, starting to develop a theme/story and finalizing a few other details. So what is left? I have 5 items that I'm currently working through in various stages, and 8 more items that I have not yet started. (This neat chart was produced by Visual Studio's free and online version of Team Foundation Server).



Tuesday, September 10, 2013

Update 17: Alpha 1.45 - Explosive Walls

I've been working on destructive terrain, and I decided the best way to blow up something, is to build it up first, literally brick by brick. As my current walls were just a (1,0.5,0.1) sized wall, I figured I should build it with 50 individual bricks into a prefab. Then when I apply force to it, it will spray across the screen in 50 pieces not one!




My first hurtle was that when I applied the rigid body property to all of the bricks, the wall tended to wobble like jelly (Jello for you Americans). I was able to solve this by not applying my RigidBody component (to enable physics) until the explosive force was applied. It actually turned out to be easier to apply this component to items in the blast radius rather than every single item on the screen. It's probably cheaper, (resource wise), too!

Next it was time to stack a few of these prefabs on top of each other, and then apply an explosive force to a random point in front of the wall... the resultant explosion was... unexpected. I'm still not sure why the explosion is along the z plane...




Moving on, applying the new prefab to my test level, it gives a far more satisfying burst across the screen when I throw grenades.




There is no download for this, I'm still adding some the next feature... which is visible in that last screenshot...

Wednesday, September 4, 2013

Update 16: Alpha 1.4: Throwing

In the last few Alpha releases, I've been focusing on stabilizing the camera and shooting mechanics. I feel much better about how it all looks, especially the camera movement, with all bugs around the camera now addressed.

Although I have a few timing issues with the shooting still to solve, I've moved on to the next type of attack, throwing grenades. I started by working through the physics and showing the trajectory. 

With the help of two very important links:

  1. Some excellent theory from the Castle Story: http://www.sauropodstudio.com/dev-diary-number-eight/
  2. A script to draw the line from Unity3D wiki: http://wiki.unity3d.com/index.php/Trajectory_Simulation

Using this, I was able to calculate the distance to the target, based on a fixed angle of 45 degrees: this meant that I can throw my grenade in a nice parabolic curve towards the target. 

Here are two screen shots showing this in action in my test level, with the red line replaced by a trail of smoke: 

Just before the grenade hits...


Just after the grenade hits...


When my grenade collides against my target, it 'explodes'. At the moment it's just an expanding red sphere - particle effects to come later. I use the Physics.OverlapSphere() function to look for items within a certain radius:

Collider[] hits = Physics.OverlapSphere(myProjectile.transform.position, explosionRadius);


If any of my collider hits are a player, I deal damage, but if it's destructible terrain, I use the AddExplosionForce() function like this:

//If destructible terrain was hit, destroy it
if (hit.collider.tag == "DestructibleTerrain") 
{
    //Add Rigidbody to terrain/wall
    hit.transform.gameObject.AddComponent<Rigidbody>();
    
    //Add explosive force at the point of the projectile impact
    hit.transform.rigidbody.AddExplosionForce(explosionForce, myProjectile.transform.position, explosionRadius);
}

This has two effects: it removes the destructible terrain from the explosion area, and it propels the same terrain across the map, which I think is pretty cool...

You can download version Alpha 1.4 here: http://www.samsmithnz.com/content/tbe/tbe_alpha1.4.zip.