Which is the best collision solid to use for a maze?

Hi, I am unsure if this is allowed here but, I am creating something which solves mazes within panda 3d, I was just wondering which is the best way to add colliders to my maze so that the character does not walk/clip through any walls? I was going to add a polygon collider but that seems like a lot of work to add each point of the polygon, I assume there is a simpler way to add a collider to the maze? Below is an image representation of the maze I am using (Its the Hampton Court Maze)
image
Any advice will be a great help.

From my experience, I think all you can do is know the x, y and z placement of all of the lines and the add a ‘CollisionCapsule’ (or ‘CollisionTube’ depending on if you want backwards compatibility or not). If you want to know the x, y and z placement, see what is the coordinate of where the maze starts and then calculate accordingly.

You can also make a first person camera (if you are not using first person cameras in the game) temporarily. Here is a code snippet that helps you do so.
https://discourse.panda3d.org/t/mini-first-person-controller-game/27050

Now, in your code, you can add the following line of code somehwere:

base.accept('g', print, [base.camera.getPos()]) # g or any key that you want if you have already used g

Now run the program and walk around. Once you have reached the point to check the position, click on g (or whatever key you used). Then take a note of all positions and make CollisionTubes accordingly

I tried this just then, it works with the first person camera but when I press g the only coordinates that it takes is LPoint3(0,0,0)

Then do it individually, for instance:

def getCoordinates():
    return (base.camera.getX(), base.camera.getY(), base.camera.getZ())

base.accept('g', print, [getCoordinates()])

#Syntax for defining the CollisionCapsule
#For defining, you have to calculate the position twice
#One at the start point, and one at the end
startX = #The x pos of the start calculation
startY = #The y pos of the start calculation
endX = #The x pos of the end calculation
endY = #The y pos of the end calculation
rad = #The z pos of any of the two calculations (because both of them are same)
collCapsule = CollisionCapsule(startX, startY, endX, endY, rad)

Though according to me LPoint3(0, 0, 0) represents x = 0, y = 0, and z = 0

Yes, but even when I am moving from one end of the scene to the other, it is still giving me coordinates (0,0,0) I am going to try the other method of doing it see if that works.

Have you called base.disableMouse()?

Yes right at the top in the __init__

panda3dmastercoder is trying to tell you to manually note down all the positions of the walls, which I don’t suggest; it’s tedious and a lot of work and possibly unnecessary. Let’s take a step back and figure out how your maze is provided or generated, which will affect the best answer to your question.

If it’s provided as a set of coordinates, then creating CollisionPolygon objects will be your best approach. If it is provided as an image, you could actually sample the image at a given position to check whether the pixel is black or white to see if it’s solid at that location. If it’s modelled in Blender, then you can generate the collision geometry from a Blender model as well.

Then use the method I mentioned. Also, I edited the code if you didn’t see

Maybe he can create a tuple which stores all tuples and calls the CollisionCapsule generation as a loop through the tuple

How do you do this? Can you tell

That is fine for a small sample program, but not at all a sustainable method for content generation.

The maze was taken from the image above as an SVG then it was converted into a mesh in blender and exported using YABEE. I used the YABEE exporter for Blender 2.8 which I learned recently is broken. Would it be worth me re-exporting the model as a .gltf? or even use blend2bam?

Actually I am not so sure of what to do as even I am a beginner to Panda3D. I was meaning to ask, are you one of the people who made Panda3D?

I use blend2bam as I have exporting issues with YABEE. My blender version is 2.9.1 (very recent)

I suggest creating the collision geometry in Blender indeed. I am not sure how it would be done in the fork of YABEE — I know in the old YABEE version you could do it by creating a Game Property called “Collide” and set it to “Polyset keep descend”, but this feature of Blender has been improved.

The method to create collision geometry in blend2bam is a little different. Consult the blend2bam documentation to learn how to export collision geometry (CC @Moguri, he may be able to give you the right pointers).

An alternative approach is to parse the svg file and construct the CollisionPolygons using the coordinates in that file. This may be an interesting approach especially if you decided to skip the Blender step and generate the maze procedurally in Panda3D based on the svg file, though this is obviously a lot more work if this is not a process you need to be able to repeat very often.

Didn’t it mention in the manuals that a CollisionPolygon can only have 3-4 sides?

To export collision solid information for a mesh, go to the physics properties for the object and enable Rigid Body physics. This contains some options regarding the shape. Keep the rigid body as Active (Passive will make it intangible) and set it to a Mesh shape. blend2bam will then create a CollisionPolygon for this object.

1 Like

I wrote some code that automatically generates Bullet collision meshes without needing to use a Blender exporter. This way, I just call it in the main loop and it will generate collision geometry for arbitrarily complex models, both .egg and .gltf

I was unaware this was an open issue with Panda3D. If anybody’s interested I can probably make a snippet post.