CollisionHandlerPusher. i don't understand

Hello!
i try use Collision System but i wrong use it: doesn’t work. i write this

from direct.showbase.ShowBase import ShowBase
from pandac.PandaModules import loadPrcFileData 
from panda3d.core import *
from pandac.PandaModules import * 
from direct.gui.DirectGui import * 

class MyApp(ShowBase):
 
    def __init__(self):
        ShowBase.__init__(self)
        
        self.cam.setPos(0, -5, 2)
        
        self.cTrav = CollisionTraverser()
        pusher = CollisionHandlerPusher()
        pusher.addInPattern('%fn-into-%in')
        pusher.addAgainPattern('%fn-again-%in')
        pusher.addOutPattern('%fn-out-%in')
        
        self.smile = self.loader.loadModel("models/smiley")
        self.smile.reparentTo(self.render)
        self.smile.setPos(0, 0, 4)
        self.smile.setScale(0.25, 0.25, 0.25)
        fromObj = self.smile.attachNewNode(CollisionNode("Smile"))
        fromObj.node().addSolid(CollisionSphere(0, 0, 0, 1.25))
        fromObj.show()
        pusher.addCollider(fromObj, self.smile)
        self.cTrav.addCollider(fromObj, pusher)
        
        wall = self.loader.loadModel("models/box")
        wall.reparentTo(self.render)
        wall.setPos(-0.5, -0.5, -0.5)
        
        taskMgr.add(self.updatePlayer, "updatePlayer")
        
    def updatePlayer(self, task):
        self.smile.setFluidPos(self.smile.getX(), self.smile.getY(), self.smile.get_z()-10*task.getDt());
        self.cam.lookAt(self.smile)
        self.cTrav.traverse(self.render)
        return task.cont
 
app = MyApp()
app.run()

but i don’t know where i wrong.
I create a CollisionTraverser and a CollisionHandlerPusher. I load a smile and make it a from object. i load a wall that, as default, is a into object. The smile move to wall thought a task function.
Who can help me?
thanks!!

You almost have it. There are just two different problems:

(1) The box.egg model that you use doesn’t have any collision geometry inside it, it’s just visible geometry. You ideally want an egg file that includes special geometry that is tagged with the flag so that it defines the solid walls.

However, you can use it anyway; it’s possible to use visible geometry as collision geometry. This is very expensive, though, so you would only do this as a shortcut when you don’t have time to make a special model and you don’t care about performance. To do this, you just set the collide mask on the visible geometry to have at least one bit in common with your from object, by adding a line like this:

wall.setCollideMask(BitMask32.bit(0))

(2) For historical reasons, CollisionHandlerPushers all have the default setting for the “horizontal” flag to be true, which means they will respond only in the XY plane–Z is eliminated. Unfortunately, you are moving the model entirely in Z in this example, so you will need to turn off the horizontal flag:

pusher.setHorizontal(False)

This flag is terribly confusing, so I think I will change the default to false for 1.8.

(3) This isn’t a problem, really, but if you want to avoid the appearance of bouncing when you reach the target, you should position the camera after the collision traversal as adjusted the position. Change your task so that the traversal and the camera lookAt() occur in this order:

self.cTrav.traverse(self.render)
self.cam.lookAt(self.smile)

David

Thanks!!! I try it asap

what do i add in the egg file to make the mesh a collider?!?!?!

The complete answer is complex, but the short answer is put { polyset keep descend } within the that contains the polygons you are interested in.

David

Where can i read more of this argument? Or how can i export a mesh from blender with collide tag?
And thanks for all :slight_smile: