Collision Events

Hi i’m having a bit of trouble working with collision events. I’ve searched the forums for hours but haven’t found a solution.

Heres my code

class Game(DirectObject.DirectObject):
    def __init__(self):

        taskMgr.add(self.TimeSinceLastFrame, "TimeSinceLastFrame")
        self.PLAYER = Player()
        
        self.CHPusher = PhysicsCollisionHandler()
        self.CHPusher.addInPattern('%fn-into-%in')
        self.CHPusher.addAgainPattern('%fn-again-%in')
        self.CHPusher.addOutPattern('%fn-out-%in')
        self.CHPusher.addCollider(self.PLAYER.PCN, self.PLAYER.PANP)

        self.Traverser = CollisionTraverser('CollisionTraverser')
        base.cTrav = self.Traverser
        self.Traverser.addCollider(self.PLAYER.PCN, self.CHPusher)
        self.Traverser.showCollisions(render)
        base.cTrav.setRespectPrevTransform(True)      

        self.Terrain = loader.loadModel("Models/0,0.egg")
        self.Terrain.reparentTo(render)
        self.Terrain.setScale(10)
        self.Terrain.setCollideMask(BitMask32.bit(1))
        #self.Terrain.hide()
        
        self.PrevTime = 0

        base.physicsMgr.attachLinearIntegrator(LinearEulerIntegrator())
        base.physicsMgr.attachAngularIntegrator(AngularEulerIntegrator())
        

        self.accept("arrow_up", self.PLAYER.MoveForward)
        self.accept("arrow_up-up", self.PLAYER.StopMovingFB)
        self.accept("arrow_down", self.PLAYER.MoveBackward)
        self.accept("arrow_down-up", self.PLAYER.StopMovingFB)
        self.accept("arrow_left", self.PLAYER.TurnLeft)
        self.accept("arrow_left-up", self.PLAYER.StopTurning)
        self.accept("arrow_right", self.PLAYER.TurnRight)
        self.accept("arrow_right-up", self.PLAYER.StopTurning)
        self.accept("space", self.PLAYER.Jump)
        self.accept('EC-into-Terrain',self.PLAYER.Land())

when I run it I get the following error.

Has anyone got any suggestions?

If haven’t carefully read your post, but at least your last line is wrong.

self.accept('EC-into-Terrain',self.PLAYER.Land())

self.PLAYER.Land() is a method call in contrast to self.PLAYER.Land which is only a pointer to a method.

Azraiyl

Thanks for the quick reply, thats lead me to a different error.

This is my “Land” method.

def Land(self):
        self.Standing = 1

Ahhhaaa after viewing the manual I realize I need to include “entry” in the variables of a method.

Changing it to

def Land(self, entry):
        self.Standing = 1

Fixed it! Now he jumps only from the ground! :smiley::D:D

…erm you don’t need to…

self.accept('key', self.myFunction)

def myFunction(self)
     ...do something here...

see how I just left out the extra argument? If you don’t need that extra argument because your function just reacts on the press of a key, you don’t need to include the extra argument. If one function should react differently on press and release of a button, you can use that extra argument…
following an example where you might want the extra args:

self.accept('key', self.myFunction, [1])
self.accept('key-up', self.myFunction, [0])

def myFunction(self, status):
    if status:
        #do something if the key is pressed...
    else:
        #do something else if the key is released...

“EC-into-Terrain” is special event created from collision subsystem. This event has one additional parameter.

On panda3d.org/manual/index.php/C … n_Handlers there is an example “handleRailCollision” which handles a collision event.

In this special case, BoZ has done the right thing.