This week I spent most of my time creating a boundary system in BGE. And now I’m looking forward to sharing it …
A small animation showing the system working: http://www.youtube.com/watch?v=P108MdGliyM
And check the blend file attached … (just open and press “P”)
How it works:
Setting the boundary:
1) I have two boundaries per object, the Inside boundary and the Outside.
2) The two boundaries are nominated following the rule: “Boundary_” + obj.name + “_I”(or “O") - (e.g. “Boundary_Suzanne_I”)
3) The boundaries are Collision enabled and have the property: "B” + obj.name (e.g. “B_Suzanne”)
Setting the object:
1) Create an Always sensor, link it to the script boundary.py and link it to a movement Actuator called “MOVE”
2) Make sure the center of the object is in the center
3) Add the objects through an AddObject Actuator (that way they all have the same name)
Now you can setup your own boundary using the script the way it is. If you need extra customization, please feel free to share the results here
Problems you may have:
- If you are parenting the boundaries to another object (e.g. the visible fake boundary in the example file), remember to apply the scale in the parent or else odd things will happen - BUG REPORT.
2)Elif the outer boundary is not tight with the inner boundary, depending on your pulse set to the sensor, the rayCast will hit the “outer face of the inner boundary”. Right now, in BGE, is not possible to check the normal of the face we are hitting (or atleast in a fast/cheap way). Therefore we have these two boundary objects, and they should be very tight.
Problems I have :o :
I’m using multiple boundaries. For each object I have a different boundary. As the rayCast function doesn’t have an X-Ray mode yet (BUG REPORT) the rayCast returns None when the boundaries of other objects are hit, even if the object is inside its real boundary.
" DEAR BLENDER GAME ENGINE DEVELOPERS (Benoit, Campbell, and others) I love your work, and I'm very happy with all the current features available in BGE. BUT please code an x-ray mode to the rayCast function (or make it the default, as I still can't see why it is different :p ). :D:):D:):D:) "
If you think this .Blend file will be useful for you, please copy this message below and post it as a commentary:
As a matter of fact, I can see a way to solve this. I need only to set different height levels for different objects, and the RayCast fromPos and toPos parameters will follow. This is however, a hack, and does not solve the other problems I’m having with rayCast
To run it properly you need the latest BlenderSVN (to use Mathutils). You can download it from Graphicall.org
Thanks to Campbell (ideasman) for the support and the sheepNav.py file, and the Apricot team and developers for the incredible work. And a big thank you to all who supports Blender and Apricot (buying DVDs, reporting bugs, coding, …).
boundary_BA_01.blend (227 KB)