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. ;)


No comments:

Post a Comment