Help with collisions and colliders

Hello to everyone reading this!

I have a model made up of various ‘cube’ elements. I read in another forum that in order to import a model directly as a collider i could add <Collide> { Polyset keep descend } to under the desired <group>. Therefore, I have done so and don’t seem to be facing any errors. Now my question is, how do I proceed from here and actually make things collide in the scene? What code do I need to write in order to do that? I’ll attach a snippet of the relevant code to this post.

self.room = self.loader.loadModel("models/gaming_room(3)")
self.room.reparentTo(self.render)
self.room.setScale(5)
self.room.setPos(30, 0, 0)

As you can see above, I haven’t really done anything to make my model a collider in the code itself but that is because I don’t really know what to do.

self.cTrav = CollisionTraverser()
ray = CollisionRay()        
ray.setFromLens(self.camNode, (0, 0))
rayNode = CollisionNode('line-of-sight')
rayNode.addSolid(ray)
rayNodePath = self.camera.attachNewNode(rayNode)
self.rayQueue = CollisionHandlerQueue()
self.cTrav.addCollider(rayNodePath, self.rayQueue

I found the above code on youtube to convert my camera into a collider. Presently, that is the only collider in my scene.

Thank you!

hello,
take a look at Bullet or ODE as Physics Engine, I had fun playing with them

(Before I answer, accaffari, greetings to you, and welcome! I hope that you find your time on the forums to be positive! ^_^)

~

@ blaze: I suppose that my primary question is this: What sort of collisions do you want to have?

Do you intend for those cubes to be only collided with–as part of the environment, for example–or do you want them to be active, moving colliders–as part of the player-character or NPCs, for example?

If your cubes are just the environment, then you may well need to do nothing more with them: they should function as “environmental” colliders just as they are.

You then just lack something to collide with them–and how that’s done depends somewhat on what it is that you want to have collide with them!

~

Hmmm… If I’m reading that correctly, the code that you posted doesn’t really “turn the camera into a collider”. With that code alone the camera won’t, for example, stay out of walls.

Rather, what that code does is set up a ray that emanates from the camera out in the direction of the camera. This can be useful for things like clicking on objects being viewed by the camera (e.g. for gameplay purposes, such as to pick up items).

~

If I may, let me suggest that it might be worth looking at the “Collision Detection” section of the manual, including the examples that it provides:
https://docs.panda3d.org/1.10/python/programming/collision-detection

(But noting that the “Clicking on 3D Objects” example shows an approach to masks–something that the manual explains–that is perhaps not ideal for general use.)

You might also perhaps take a look at the section in my “Beginner’s Tutorial” that covers collision:

(There’s more on collision in that tutorial, but the above should be a starting point at least, I think.)

Do you intend for those cubes to be only collided with–as part of the environment, for example–or do you want them to be active, moving colliders–as part of the player-character or NPCs, for example?

I intend to use the cubes as part of the environment. The player would be able to collide with it, much like a wall.

I did go through all the available documentation for collision detection but it didn’t really help my case too much. I must also say that I am a beginner to such projects and am doing this only for a school project. I’m just trying to learn things as i progress through this project, although now I do realise that that may not be the best approach to this lol.

I did also go through your tutorial a while back and was able to understand a lot more. However, I wasn’t exactly able to apply it in my project.

Anyway, I think I know why my character wasn’t colliding with the cubes now.

Any further advice will be much appreciated!

@accafari Bullet is like a whole new universe within panda3d :sob:. I’m afraid i wouldn’t be able to make much progress with it.

Regarding Bullet, etc., honestly, unless you need actual physics–as opposed to simple collision and keeping your characters out of walls–I might suggest sticking with the built-in collision system for now.

The built-in collision-system is, I think, a little simpler to use than full physics systems like Bullet. Further, I daresay that for non-physics purposes it’ll tend to be a bit more reliable, at least for cases that aren’t complex.

Different people learn in different ways! It may well be that your approach will work for you–at the least see how it goes!

Ah, that’s good! Did you get it working, then? What was the problem?

I think that the main advice that I might give at this point is to, when choosing “from”-colliders, stick with spheres as far as feasible–they’re fast, (usually) reliable, and collide with most other solids. Where spheres won’t do, consider capsules.

(Of course, rays, segments, and lines tend to be very fast–but are limited by the nature of being simple lines. Still, they very much have their uses, I find!)

Beyond that, it’s hard to give concrete advice without knowing what you’re working on–and you may learn simply from trying things!

thanks Thaumaturge,
I really enjoy panda3d, I had a “full immersion” a couple of months ago, and this forum was a great place where clarify some doubts. I’m impressed how Panda3d is powerfull and intuitive, I thought it would be much more complicated but it wasn’t.
I have tried almost everything successfully, the goal was to skip from GeoMipTerrain to MeshShaderTerrain with my own glsl for lights , shadows and PBR materials.
I satisfied all my curiosities but I found my limitations, which are the lack of creativity and patience to create models and develop original shaders and finally the complete lack of a project idea … lol
Thank you to all the speakers for the excellent work on this forum

1 Like

accaffari, I’m glad that you’re so enjoying the engine, and that you’ve made such progress! :slight_smile:

As to models and suchlike, I’d suggest looking for freeware models that are either in a Panda-compatible format (e.g. gltf), or that can be converted to one. That way you don’t have to worry about making your own!

As to project ideas, you could always ask around your social circles or dev circles for ideas

Alternatively, you could maybe look to work with someone who already has an idea for a project, with you as the programmer and them as the artist.

Anyway, good luck with whatever future journeys you take in game-dev! :slight_smile:

1 Like

Journeys is the exact word to describe my trip, here is a picture from my last place.
Moon only because it’s the first good result when I searched for heightmaps on Google :sweat_smile:

1 Like

That is pretty cool, and nice work! :slight_smile:

1 Like