How do you setup Collision for walls?

Hello, anywho am having some problems figuring out how to set up walls for my game. Its a simple game where a character walks around in a maze. Right now my character can walk through walls, and am trying to figure out how to stop that.

I kind of get how to attach CollisionSphere to models and how to make a pusher (so if object one walks into object two they push against each other). But the thing i don’t get is how i can apply that to a wall, since a wall isn’t a sphere and attaching a Collision solid to it wouldn’t work (since the character in it and it isn’t in any normal solid shape).

Any advice or help on this issue would be great, thank you for your time.

Hello, anywho i was able to figure out that i needed to attach a CollisionPlane to my maze model for it to work, however, it seems the CollisionPlane i attached isn’t working correctly.

Currently i have something like this:
wNode = CollisionNode(‘mazeWall1’)
#Left Wall
wNode.addSolid(CollisionPlane(Plane(Vec3(1, 0, 0), Point3(5, 0, 0))))

Which is suppose to keep the Actor inside the maze, since this Collision is for the left wall. However, it does the opposite, and keeps the Actor outside the maze. I tried using CollisionPolygon instead, but they are also problematic, since they appear to have a one-way Collision detection (If i trying moving through a CollisionPolygon left to right it blocks, but if i try to move right to left, it allows).

Anywho i was wondering if anyone knew how to correct this error, any help would be nice.

Planes are directional, so the simple answer is to flip your plane the other way around:

wNode.addSolid(CollisionPlane(Plane(Vec3(-1, 0, 0), Point3(5, 0, 0))))

But since Planes are also infinite, I doubt this will be very useful to construct the walls of a maze, since your maze walls have to be finite so you can walk around them.

So, use CollisionPolygons. As you have observed, these have a directional property: they’re only solid from the front side. If you want to have a wall that’s solid from both directions, you will need to use two CollisionPolygons, one facing each direction.

But you will have some problems with back-to-back CollisionPolygons. If your avatar intersects two walls at once, the collision system won’t be sure which direction your avatar came from, and might yank it all the way through the wall.

One way to reduce this problem is to put a little bit of space between your back-to-back walls, so that you will never intersect both of them at once. The right amount of space is a little bit more than the minimum distance your avatar might penetrate within the span of a single frame.

Another way to reduce this problem is to turn on the fluid movement detection, as described in the manual. Then the collision system will know the direction your avatar is moving, and will know to ignore walls that are facing in the wrong direction.

I recommend using both of the above solutions together.

A third solution, which requires a bit more work in the Python code, is to selectively enable or disable walls according to where your avatar is standing within the grid. For instance, you could examine your avatar’s X, Y position and know that he’s standing at block (4, 5), and therefore there should be a north wall and an east wall here. All of the other walls can be disabled (for instance, by stashing them). This will not only avoid problems from inappropriate collisions with backfacing walls, but it will also improve performance by reducing the number of walls the collision system will have to test against. Of course, you’ll have to figure out how to write the algorithm that determines which walls should be active based on your avatar’s position.


You could also just enable collisions on your wall geometry.


But of course this will be very expensive with non-optimised geometry.
Which is why I use the octree builder from raytaller:

to seriously optimise the performance of collision detection against geometry.
The only thing you need to do once you’ve got an optimised mesh is to load it from the resulting file, hide() it and enable collisions on it.

This method works beautiful for me, I have collisions against multi-k poly meshs.