Check collision on a model

Right now I have self.obstacle = loader.loadModel(sphereObstacle)

And then I place it in the world and I want my character to collide with these obstacles. How can I check collision between the player and these spheres? There are multiple instances of these spheres for this mini-game and they are randomly placed throughout the level.

Would it be if (self.player.isCollide(self.obstacle)): #Do stuff

Or something similar. Thanks.

Section T in the manual describes how to do collision detection in panda. Using attached collision solids is generally faster than doing checks against native geometry. If panda’s built-in detection isn’t adequate, you could always try pyODE.

Ok, so my next issue is that once the player runs into this object, how would I delete the object from the screen. If I try self.obstacle.destroy() it says that it’s not a parameter of the Node, I don’t have the error on hand at the moment but I’m guessing I can’t delete or destory the model or at least make it invisible/non-collidable.

In short, how do you destroy a loader.loadModel() object, remember that there are more than 1 of these so I can’t unload the model and I’d rather not have a ton of the same object loaded so I can unload them one by one.

Hi, ynjh_jo, created a nice example of what you want to do (“pick objects” ) upon detecting collisions. I hope this thread helps you:

https://discourse.panda3d.org/viewtopic.php?t=2508
best o’ luck

Use loader.loadModelCopy() instead of loader.loadModel() if you are loading multiple copies of the same model. This method will try to load from the cache first, which is faster than loading it from the disk every time.

If you want to remove a node from the scenegraph, you can just use self.obstacle.detachNode() for the obstacle you want to remove. See section A in programming with panda in the manual for basic scenegraph manipulations.