The premise is simple: The player will be placed in the center of an inescapable arena, where he will face enemies that are endlessly spawned from one of four entry-ways. The object will be to survive for as long a period of time as possible. As the project progresses, I will undoubtedly decide to add random features to the game, such as multiple weapons, multiple enemies, pick-ups, so forth.
Something I feel must be clarified: This project is a learning experience, first and foremost. As such, this journal isn't so much to display some great work, but more for journaling and sharing with you my personal accomplishments. Feel free to leave your comments and criticisms. Now, onto the project:
I began by using some of Unity's primitive GameObjects (Cube, Sphere & Cylinder) to prefab fillers for my games key components (enemy, walls, entry ways). I then developed a stand in object for the player, and basic movement script. Testing this, everything was fine. All colliders and rigidbodies in place, time to start some very primitive AI (if you would even call it that)...
Pretty easy, using Unity's LookAt() and transform.Translate() functions, enemies will face me, and move forward. Test it out, works fine. ((Unfortunately, Translate() ignores colliders and rigidbodies--at least dynamic ones--so I'll have to deal with that... a little later)). I make a small sphere to stand in as a bullet that destroys itself upon collision or 1 second (whichever's first), and going back to the enemy AI scripts, when triggered by colliding with the bullet, the object deactivates it's full body collider, all of the bodies separate segments switch their rigidbodies to non-kinematic and add a small explosive force. After 2 seconds, the object destroys itself. To test this out, I add a small "shoot" script to my player that instances a bullet when the space bar is pressed. The bullet, having a constant force in the direction faced by the player, is shot. Start the scene, shoot the nearest enemy coming toward me, presto! He falls to pieces and disappears.
Next step, instancing enemies through the doorway. This is my first real task, as I've never done this. I attach a script to the entry way specifically for spawning enemies that uses the Instantiate function to place one at the same space as the entryway. Test it out, and poof, an enemy in each entry way seeking me out. So, going back to the EnemyAI, on they're death, using an array and for() loop, each entry way spawns a new enemy. And here, I reach a conundrum... Killing one enemy, spawns four, and I'm quickly filling the arena up with enemies. Furthermore, with the Translate() function used to move enemies ignoring dynamic colliders, enemies are occupying the same space, making a single bullet kill two or three enemies at once, spawning 3 enemies at each entry way, already occupying the same space...
First, to eliminate the mass amounts of enemies, a static variable in my spawner script, to limit the max enemies. A simple if() statement maxes out the amount of enemies that will be spawned at any one time. ((Here I messed up and forgot to decrease the enemy amount when one's killed, quickly fixed that.)) That still left me with them being spawned on top of one another being an issue. After a little reading on the RayCast() function and some testing, I used the function to detect for enemies within a reasonable distance of the entry way, only instancing if the result came back false.
At this point, everything is working within reason (except for enemies moving over one another). Just to put that off slightly longer, I replaced the sphere I'd been using for a bullet, with an actual bullet model. Importing the accompanying empty casing model and coupling an Instantiate() and AddForce() call into the shooting script, a real bullet is shot, and a shell casing ejected. Here, I deleted the cube/cylinder/sphere model used for the player and for the time being am simply a floating entity.
Enter, Bob... Using the same skills learned by adding the bullet and shell casing models to the game, I chose a zombie model to use as my basic enemy. It should be noted hat the model is not animated or rigged (when you download free models, you get what you pay for.)
And now... you're up to date. I personally don't think that's bad for a day's worth of work doing something one's never done before. Before I go any further, I'm going to correct my code to prevent enemies from occupying the same space. Will add another entry at that point.