Search Results

Tuesday, July 5, 2011

BGHelper Module V1.3

Hey. So, here's version 1.3 of the BGHelper module. In case you didn't know, the BGHelper is a module for use with the Blender Game Engine intended to make complex tasks easier. The new features are Callbacks and Collision Detection.

- Callbacks

So, say you're making a game. You want to play a sound when the Player steps on an object or panel. Okay, that's not that complex. However, you only want to play the sound in one frame, should the Player step on the panel, and each time, as well. It's a bit complex, so I made the Callback class.

Callback objects makes this process simpler by allowing you to run functions should a condition change, and only then. After this frame, the callback object stores the previous value, meaning that if the Player steps on a panel, it will be a change only for one frame (if the Callback object's Update function executes every frame).

For example, you can create a callback whose job is to check a simple function that just returns the current panel under the Player - if it changes (from None, for example, to another object), then the callback object will run a returning function - one that you specify. Here it is in easier terms:

def GroundChange():

      print ('the ground changed')

obj['callback'] = CCallback(lambda : return ground[0], GroundChange, ...)


In this example,  the callback function will run the 'lambda' function defined above to check the value. The lambda function is just a simple, shorthand version of a normal function definition in line - it's just easier to type in. If the value of ground[0] changes (what the lambda function returns), then it will run the GroundChange function and print 'the ground changed' to the console.

- Collision Detection

This version of BGHelper adds a CBoxBounds object class that allows for Python-level collision detection (not Bullet). It can check for collisions between two different BoxBounds objects, or between a point (list or Vector) and a BoxBounds object. Objects will also add to a collision property (assuming that box = CBoxBounds(), you access it with box.collision) that you can check to see what the object is colliding with.

That was a lot of text. So, download BGHelper V1.3 here.

No comments:

Post a Comment