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.addCollider(self.PLAYER.PCN, self.PLAYER.PANP)

        self.Traverser = CollisionTraverser('CollisionTraverser')
        base.cTrav = self.Traverser
        self.Traverser.addCollider(self.PLAYER.PCN, self.CHPusher)

        self.Terrain = loader.loadModel("Models/0,0.egg")
        self.PrevTime = 0


        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)

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.PLAYER.Land() is a method call in contrast to self.PLAYER.Land which is only a pointer to a method.


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) 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...
        #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 … n_Handlers there is an example “handleRailCollision” which handles a collision event.

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