Sunday, June 17, 2012

Rocket Tank - Fun with Physics

The main mechanic of this game is that rockets will bounce off of walls. The player will have to judge their bank shots correctly in order to hit a certain target (or avoid hitting other targets). This will all be made possible by this Physics-related type thing called the Law of Reflection.


This law states that a ray cast towards a surface will reflect off of it at the same angle it hit: like in the diagram above, the angle of incidence will be equal to the angle of reflection.

Though the law of reflection initially applies to light rays and specular reflection, it can also be applied to the trajectory of moving objects. If you think of a game such as "Breakout," this law holds true: the ball bounces off of a wall at the same angle it hit it. Now this effect is easily reproducible for round objects (such as a ball or sphere), but I'm trying to bounce cylindrical rockets (which actually have a simplified rectangular collision mesh). The collision system won't naturally allow a box to reflect in this manner, so I get to force it manually. Fun.

So, does this equation look familiar to you?


Unless you watched the video I did on the kart racer's artificial intelligence system and paused the video at this exact point with the express purpose of knowing and learning this equation, probably not.

But here's where the kart racer's AI system comes in. Part of the script includes an equation that outputs an angle measure when given two vectors. The two vectors I worked with were the kart's world orientation vector (what direction it was pointing in), and the steering vector (which pointed in the direction the kart needed to go).

The exact same mechanic applies here. I still have to calculate the angle between two vectors: only this time, between the direction the rocket is facing with the direction the wall is facing. I can get these by grabbing the rocket's world orientation vector and the wall's surface normal.


The only trouble I foresee is actually rotating the rocket. With the kart's AI, the script ran continuously because it always needed to steer the kart. But to control the rocket, I have to save the calculated angle and rotate the rocket by that amount the instant it collides with the wall, then recalculate the angle for the next collision. I'm not immediately sure how to pull this off, but I'll see when I get there.

Wednesday, June 13, 2012

Rocket Tank - Cursor Control and Particle Effects

I've added some basic functionality to the game. There's now a crosshair shown on screen that will follow the mouse. The gun from the tank will always point towards this crosshair, so that the player can actually aim their rockets. (Ya know, aiming is usually a good thing in a game where you have to shoot stuff.) I'm considering also rendering a laser sight that will make it easier for players to judge the angles of their shots, but only if it's absolutely necessary. Rendering a good looking laser seems pretty difficult.

Also, I tried messing with an addon for Blender called EasyEmit: it's basically a particle system designed to work in the game engine. I was able to tweak it to get a good flow of fire shooting from the back of the rocket. 


Just one little problem though- when the rocket object ends, the flame particles just freeze in midair and stay there. I'm guessing this is because the particle emitter is simply parented to the rocket, and gets deleted along with the rocket. This leaves the emitted particles to freeze, since the emitter object that tells them what to do is gone. Not sure what to do about that; I'll have to look into it.

I'm also working on a custom particle explosion using EasyEmit- it's pretty easy to use and implement (hence the name EasyEmit :P), and it's great that I can get some decent looking particle effects even with the presets.

The next thing to work on would be the actual rocket-bouncing mechanic. This will be a bit tricky, but I realized that I can actually use part of the code from the kart racer's AI system and implement it here. I'll explain it more in depth in my next post. Until then..... lemons. Don't take 'em.

Tuesday, May 29, 2012

New Game Project - Rocket Tank

Hey guys, it's been a while. Anyway, since I've parted with the kart racer for now, I've started a new game project. I haven't come up with an official name for it yet [figures], but it's prototype name is Rocket Tank.
















Rocket Tank will be more of a puzzle game. You play as a hover tank which can shoot rockets in any direction. The catch is that rockets can bounce off of walls. This will be the main puzzle aspect, as the player will need to think carefully about how to correctly bounce their rockets in order to hit an object and avoid obstacles.

The game will feature other elements such as laser turrets (a particularly ugly-textured work-in-progress of which is shown in the screenshot), switches that open doors and toggle other elements, various wall types with different rocket-bouncing properties, and possibly different types of rockets with different properties or perks. 

The goal is to properly deal with these elements in order to safely reach the end of each level [marked by the yellow and black striped area at the end]. The game will hopefully feature several levels, which comfortably introduce the main mechanics of the game while progressively getting more difficult.

The basic mechanics of the game are still in the works, as I only conceptualized this project a few weeks ago. That being said, its basic functions (such as aiming and bouncing the rockets) aren't functional. At least not yet. Still working on that. Once they are, though, I'll probably post a gameplay video to show what it looks like in action.

Hopefully, I'll learn a lot from taking on this project, as I've gained a massive amount of knowledge after dealing with- I mean, creating- the kart racer. I look forward to taking on the challenges that come my way, and hopefully the game will be good enough to the point where it can be socially accepted as "fun." We'll see how that goes.

Tuesday, May 1, 2012

Kart Racer - Wrapping it Up

Hey everyone, it's been quite a while since I've posted here.

















Anyway, I originally created the kart racer for my senior project, of which I've now passed. :D 

The thing is, even though it is unfinished, I think I'm gonna be done with it for now. Creating this thing has been a huge challenge [*coughcoughartificialintelligencecough*], but in the process, I've learned a lot. I guess I've grown tired of dealing with this specific project, though I may come back someday to revisit and improve it. Who knows? I sure don't. I've got other game projects in mind that I'd like to try, so this one is pretty much done for now.

I'm making the .blend file available for download. This way you guys [well, whoever actually reads this pathetic excuse of a blog] can explore the file and see how it's set up. As an added bonus, you can even be stultified to death by staring confusedly at the ridiculously irritating and convoluted AI system I somehow managed to throw together! Fun!

Just a note, the file really only works in Blender 2.61. For some reason or another, the whole AI system glitches up when bringing it into 2.62 or later. Just a warning.

Also, if the link ever goes down for whatever reason and you want me to re-upload it, just shoot me an email at mechacorestudios@gmail.com. I'm sure I'll respond eventually.

Well, it's been fun. I might just announce another game project soon.... just a heads up.




...and you know what I just realized? I never came up with a real name for this thing. I still refer to it as "Kart Racer." Oh well. Guess I'm not good with names.

Friday, March 2, 2012

Kart Racer - Artificial Intelligence Video


This one explains the AI more in depth. I've posted about the AI system while working on it, but the way in which I presented it was pretty convoluted [not to mention that the system itself is really complex.] Hopefully this will make it easier to understand.

Saturday, February 25, 2012

Kart Racer- Introduction Video

Well, looks like I finally got that screen capture software.


Yep, I've finally got it on video. This introduces the game's basic mechanics and shows off the second level in the game, SawShark Beach. 

My next video will be about the AI system. The way I've explained this before in previous posts is a bit convoluted, so hopefully it'll explain the system in a much clearer way.

Also, I've got a Facebook page. Like it. :D

Saturday, January 28, 2012

Kart Racer- Winter Track Aesthetics + Yet Even Still More AI

First off [although not nearly as important], I've been experimenting with a few lighting concepts for the winter track. As you can see, I overhauled the lighting and skybox to a dusk setting [rather than mid-afternoon]. I really love the mood this sets, and it really helps the track stand out.














As for the AI, I've made some progress- the AI kart actually goes all the way around the track. Yep, that's right. Full 360.

In order to do it, I had to set up three targets around the track. The kart tracks to the first target and switches to the next once it gets within a certain distance. It will loop endlessly between the three targets, making it go all the way around the track.

However, the way in which I approached this wasn't my preferred method. I wanted to have just one steering actuator that would update the target automatically, but it always switched back to the previous target [and I couldn't figure out a system to prevent this]. Instead, I tried a state system in which it will switch to a new steering actuator in an independent state, thus [hopefully] preventing it from turning around. This eats up considerably more logic, though.

The system isn't perfect, as sometimes the kart won't think it reached the target and will turn back. It happens sporadically, so it's hard to tell exactly what's happening and how to fix it. Also, the system isn't versatile at all. I have the feeling that integrating this into the other tracks will be a nightmare. I don't have much time on my hands though, so it will have to do.

Also, I'm planning on getting screen capture software some time in the near future. This way I can actually post some footage of the AI in action. Just a heads up.

Saturday, January 7, 2012

Kart Racer- Audio Department and Yet Even More AI

Today I've started to work on some audio related aspects.

First off, I've added a crashing sound that will play when you bump into a wall. There's also a separate sound that plays when you crash into a tree [leaves rustling, etc.] I was hoping to trigger the sound only if the kart was traveling at a certain velocity before impact, but I couldn't get it to work properly. It seems fine the way it is.

Also, I've finished another track for the game. This will play at the main menu screen and at the results screen shortly after a race. I kept this one short, as the player won't hear it for too long anyway.



Next, I'm starting to conceptualize a system for when the player finishes three laps. Basically, the player kart will be swapped out with an AI kart after crossing the finish line, and the view will switch to a different camera that rotates 360 around the kart. This is when the menu track will fade in.

As far as artificial intelligence goes, I'm currently trying to figure out how to switch to the next target once it gets within a certain distance of the first target. Because the kart goes in a closed loop, it needs at least three or more targets placed around the track to go all the way around. That's it for now.

Tuesday, January 3, 2012

Kart Racer- Ignore that Last Post Regarding AI...

Well, I think I did it.

I already know that the steering actuator overrides all object movement- but I've finally thought of a system that compensates for this.

Basically, whatever calculates the steering vector must be a separate object from the kart, and also must constantly alternate between two states: one lets the steering actuator do its thing, and the other corrects it's position/orientation after the actuator moves it. This way, there's no conflicting movement that cancels out the steering actuator. This is done by a ghost object that won't render on-screen.

The ghost object alternates between its two states: in State 1, the steering actuator moves the ghost object and saves the steering vector as a variable [it saves this variable in a global directory so the Vehicle Wrapper script can access this value.]  In State 2, the ghost no longer calculates a path and aligns to the kart's worldPosition and worldOrientation. This way the steering vector in State 1 is accurate [well, not really, but close enough] to the kart's position. Upon returning into State 1, the ghost will update its path.

And it seems to work; although it's going to need a lot of tweaking to look natural. When the ghost object is resetting its position in state two, the steering vector reverts to zero- meaning that the kart's wheels will constantly straighten out every other logic tick. [which is, for those of you who don't know, about 30 times per second.]

It also seems to eat up a lot of logic- with this system running on one kart, the logic calculations jumped from 3% to about 8%- a 5% increase for each kart [basic math subtraction skills FTW!]. This doesn't sound like much, but once 5 AI karts are implemented, it will cost about 25% of total game calculations, which is a lot [one fourth, to be exact.] Hopefully I'll be able to modify and optimize the code to get this implemented and running smoothly.

Well, after seeing karts turning left for so long, it's awesome to see that AI is finally getting somewhere [more specifically, not left.] I shouldn't get too excited though, as there's still a lot ahead of me.

Wow, that's a big wall of text. I promise that the next post will have screenshots. Although I'm not promising anything. ;)


Kart Racer- AI Trouble

Okay, after testing out the steering actuator for quite a while, it seems that I simply can't integrate it with the vehicle wrapper. The actuator must be in charge of moving an object or else it won't return a steering vector.

Due to this,  I need to either find a completely different method to steer, or just scrap AI all together and focus on local multiplayer or a time trial mode.