Saturday, December 31, 2011

Kart Racer- Quick Improvments

Over a few days, I've made a few quick improvements.

First, the aesthetics. I've designed a conceptual HUD [heads up display] for the game, including the race position the player is in, a timer, and "Get Ready..." and "Go!" text that displays as the race starts. However, the race position and timer are just placeholders- static text that doesn't change. This way you're always in first. Not much of an accomplishment seeing as the AI insists on turning left all the time.














Also, a few technical improvements- the first being that I finally added an invisible wall around the island in SawShark Beach. This prevents the karts from driving... on water. Guess I never really got around to kart water physics.

Next, I've changed the way to control the kart's speed. Before, I simply capped the kart's velocity when driving. I also lowered it when the kart went off-road. For example:

car.linVelocityMax = 65.0
    if road.positive == False:
        car.linVelocityMax = 40.0

Unfortunately, this method proved to be clunky, as the kart suddenly slowed down when driving into grass or sand. I needed to make the speed transition more natural. So I came up with this instead:

elif gas.positive == True:
       
        if (carspeed.y >= 65.0) and (road.positive):
            power = 0.0
           
        elif (carspeed.y >= 40.0) and (road.positive == False):
            power = 0.0
           
        else:
            power = -gasPower

This will change the kart's engine power [gasPower in the script] according to certain conditions. Once the kart has reached a velocity of 65 on road, the engine power will be set to zero until the car slows back down. It does the same when off road, but sets it to a lower speed. This effectively caps the top speed, and makes the slowdown feel natural when driving into grass. It will also make designing the mechanics of the boost power-up much easier. 

That's it for now. Still working on that artificial intelligence.

Tuesday, December 27, 2011

Kart Racer- AI Overhaul

Well, after a lot of testing, I've got bad news. It seems that the steering actuator overrides all object movement [with the exception of the simple motion logic brick], making it impossible to integrate directly with the vehicle wrapper.

There might be a work-around, though. My thought is to have a 'ghost' object which the steering actuator will be applied to. The ghost object would copy the 'worldPosition' and 'worldOrientation' of the kart, and would send its steering vector back to the VW Powertrain script. This way, the actuator won't control the kart directly, but will guide it instead. 

This could theoretically work, but I'll have to test it. 

A lot.

Wednesday, December 14, 2011

Kart Racer- AI is Almost There

Well, I made a major breakthrough today. Finally, some good news for once.

After posting the 'vector to angle' problem on a physics forum, I was suggested an equation that works! Those guys were fast too; they replied in less than 24 hours, so kudos to them.

Here's the equation formatted in Python, for any coders out there:

steervec = cont.actuators['Steering'].steeringVec
kartvec = kart.localOrientation[1]

kx = kartvec.x
ky = kartvec.y
sx = steervec.x
sy = steervec.y

nkx = kx / math.sqrt(kx**2 + ky**2)
nky = ky / math.sqrt(kx**2 + ky**2)

dkart = -(nky)*(sx) + (nkx)*(sy)
print(dkart)

turn = 0.06

if dkart < 0:
    turn = turn

elif dkart > 0:
    turn = -turn

else:
    turn = 0.0


To be honest, I don't fully understand how this equations really works; but to my knowledge, it rotates the steering vector to match the kart's local vector, than relates them from there. It works wonderfully- it returns positive values when steering right, and negative values to steer left. Just what I was looking for.

However, it's not fully functional. Yet.

It seems that the steering actuator is overriding the Vehicle Wrapper. Basically, the wheels are turning and the gas is cranked, but the steering actuator stops it in it's tracks and forces it to go the set 'velocity' setting. To get this to work properly, I have to find a way to override this. Other than that, basic steering AI is almost done!

Monday, December 12, 2011

Kart Racer- Testing the Steering Actuator

Let me introduce you to Blender's Steering Actuator:





















This actuator finds a target object [in this case, Target1], draws a path within a defined area [NavMesh], and then steers the object along this path in order to reach the target.

To help troubleshoot/fix the current AI, I decided to test the steering actuator with just a cube. This would rule out any variables that the Vehicle Wrapper might have caused. This is what I figured out.

The steering actuator not only steers an object left or right, but is also responsible for physically moving it forward [by means of a 'velocity' setting]. If the 'velocity' setting in the actuator is set to 0, it won't respond- meaning it won't return a steering vector [which is essential for steering the kart.] This is simply due to how the actuator handles velocity- if it's set to 0, it assumes it's not going anywhere, so it doesn't bother to return this vector even if it is physically moving.

Before I discovered this, I set the 'velocity' value to 0, since I wanted the VW to take care of forward movement. As a workaround, I tried setting it to a ridiculously low value [0.001] in order to get the actuator to respond without affecting forward movement too much.  It actually worked when I propelled the cube separately by means of the simple motion logic brick, and the script I wrote correctly returned the steering vector. 

However, it still won't return a steering vector when applied to the Vehicle Wrapper, so something in there is conflicting. Even once I do get it, I still need to find a way to manipulate this vector to steer the car left or right. Looks like there's a lot ahead of me.

Thursday, December 8, 2011

Kart Racer- Artificial Intelligence Focus

I've realized that I really need to get going on coding a functional AI system. 

And fast.

The deadline for this project is about April or May- which may seem like a long time, but it really isn't. There's still a lot to do both aesthetically and technically in only 5 or 6 months [and everything I've done so far took about the same time.]

For that reason, I'm going to focus exclusively on programming AI for this month [and into January, if necessary.] Once it's out of the way, it will be much easier to create the other levels and incorporate new features.

When I started this project, I knew that this one aspect could be the downfall of the whole project. I could have just created a simple puzzle game, but I was willing to take the risks and do something much more complex.

So until I have a functional AI system, it's going to be all technical posts ahead. I apologize for the more artistically inclined viewers who don't want to hear the technical stuff, but it has to be done.

Monday, December 5, 2011

Kart Racer Progress- November 2011

I actually did a lot for this month.

First, the aesthetics. 




















SawShark Beach was in desperate need of a facelift. The environment [mostly the rock walls] were tweaked and distorted to give that 'wonky,' cartoonish look that made Diddy Kong Racing stand out. Ambient occlusion has been baked to the cliffs, tunnel, and road. The waterfalls were also given a much better texture, and mist spawns where they hit the water.

To make the tunnel stand out more, I tried overlaying a custom gradient over the rock texture. This is essentially "painting on" the lighting, and this technique was used extensively in DKR as well. I'm pretty happy with the result, and I'll probably incorporate it into the cliffs as well.

Next, there's been significant progress in the [usually under-looked] audio department. I've composed a track for SawShark Beach. I tried to tie in elements of Dave Wise's work from DKR [namely the tracks for Crescent Island and Whale Bay] while still keeping it original. I think I did a decent job.





The water falls now emit the sound of- well, falling water. The kart also has an engine sound now- I've tweaked a script that changes the pitch of the sound dependent on the kart's velocity. And the sound I used for the engine? It's a processed vacuum cleaner. No kidding. I couldn't find a decent engine loop, so it works.

I've made some technical progress as well. 

First up, I wrote a script to give a random rotation to the waterfall mist planes. Before this, they all faced up, and it was noticeable. This gives it a bit more variation.

Next, I created a script that manages tire debris [when you drive in grass, green clouds emit from the back tires, sand emits yellow clouds, etc.] I want them only to spawn when the kart is moving, but for some reason it keeps returning errors. I'll figure it out eventually.

Finally, I went back to the Vehicle Wrapper for some tweaks. I found out that I accidentally assigned the emergency brake to the down arrow key. I wanted to swap this out for the regular brake, then get rid of the E-brake's funcionality, as it was not needed. Easy, right?

Wrong.

Now the same button that is used for braking is also used for reversing. Long story short, you can't back up. Big problem. I had to rearrange a lot of 'if' statements, and it got confusing fast. I think I eventually got it to work, but it only backs up on grass or sand. It won't reverse on the road. And I have absolutely no clue as to why. Again, I'm still working on it, and I'll fix it soon.

Alright, it looks like I'm finally up to speed. Future posts won't be nearly as long, as I just wanted to sum up what I've already done. I've already done six months of work, but this project is just getting started.

Saturday, December 3, 2011

Kart Racer Progress- September + October 2011

The first thing I tried was to create Racing AI [Artificial Intelligence].

The AI would not only have to follow the track correctly, but also had to pick up weapons/items and use them appropriately. Obviously, the first thing I started off with was basic movement.

Luckily for me, the newest version of Blender was released [2.60], and it featured integrated path-finding and a brand new steering actuator. The problem was integrating this new feature with the Vehicle Wrapper [abbreviated as VW].

[Warning: Technical stuff.]

This gets pretty complex, but I'll try to make it simple. The steering actuator tracks to a target object while staying within the bounds of a separate navigation mesh. However, this actuator would move and rotate the object directly. My idea was to send the velocity/steering functions of the actuator to command the gas/steering functions in the VW. This way the AI kart would steer realistically, and would be subject to the same movement/constraints as the player kart.

For the time, I simply set the gas to always be on. Easy enough. The steering, however, was much more difficult. The steering actuator generates the values to turn in the form of a vector- I wanted to take this vector and relay it to the VW. Basically, I set it up so a positive vector would make it steer left, negative would steer right, and a value of zero would keep it going straight. However, this simply didn't work. The kart just drove in circles. 

[/Technical Stuff]

Semi-frustrated with this, I decided to move to the art side and start modeling levels. The first one I started will actually be the second track in the final game. Welcome to SawShark Beach.

































This is a basic beach/island themed level. It features a cave area, a few palm trees, and four waterfalls. The screenshots don't show much, but it's there.

On another note, I happened to discover [well, invent, really] the unnatural phenomenon of perpendicular gravity. Basically, I implemented a UV scroll script to move the waterfall texture down to look like- well, a waterfall. Amazingly, it went sideways. XD

















I also sketched out and modeled the third track, a winter themed track [name pending.] Not much detail in this one yet, just basic walls and a road. The shape is interesting in that the track loops over itself to form a figure eight.

















As you can also see, I created some textures for the kart itself. Most of the work I did during this period was aesthetic, so not much logic/programing was accomplished.

Kart Racer Progress- June through August 2011

I began to work on this game in late June, and here's where I started off.

I decided to base the art style and mechanics of the game off of Diddy Kong Racing for the Nintendo 64, but while still keeping it original. [I'm not a big fan of Mario Kart. Four words- "Rubber-band AI" and "blue shell". Enough said.]



















I started by modeling a quick kart and setting it up with Blender's Vehicle Wrapper. I modified the code so you can press 'z' in conjunction with the arrow keys to turn more sharply [in order to compensate for the lack of analog control]. After some slight tweaking, it worked great on the flat plane I set up.

And then I modeled a quick track for it.
















There was an immediate problem- the physics were just awful. Because track was now banked, the kart would bounce around uncontrollably- no consistency whatsoever. Heck, it could even ride alongside the walls [SpiderKart?- could make for a neat game mechanic, but that's for another time.]

Thanks to the guys at the BlenderArtists forums, I got something manageable. The main fixes were:

-Adding a couple levels of subsurf to the track to smooth it out
[Or create a higher-poly invisible road mesh to calculate physics]
-Increase world gravity [to compensate for inaccurate scale]
-In the Vehicle Wrapper, increase suspension stiffness and lower tire grip
-Increase rotation dampening in the physics settings
-Add an orientation constraint [logic brick] to prevent kart from flipping over
-Capped velocity to determine top speed. [Also lowered max speed when driving in grass, sand, etc.]

These greatly helped to make the kart drivable. Next was to start creating levels and start one of the hardest aspects of the game- racing artificial intelligence.


Welcome to mechaCORE

Hey everyone, and welcome to the blog for mechaCORE studios- my personal and independent game studio. This blog is mainly to post updates about any games I'm working on.

With that said, my current project is a kart racing game. I still haven't given it a name yet, so I'll just refer to it as "Kart Racer" until I come up with something decent.

This game utilizes the Blender Game Engine. I'm doing all of the programming, modeling, texturing, and sound design myself, which is quite a workload for one person.

I actually started working on this game in June 2011- so the next few posts will summarize what I've already done. Once I've caught up, I'll post more frequent and smaller updates. I'd like to use this blog not only show current progress, but also discuss what problems I'm faced with and how I overcome them. Hopefully this will help someone who might be tackling a similar project.

If you have any questions, feel free to email me at mechacorestudios@gmail.com.