BoZ
September 23, 2007, 9:55am
1
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.
Commandline: ppython C:\Chaneciya\Main.py
Workingdirectory:
Timeout: 0 ms
Known pipe types:
wglGraphicsPipe
(3 aux display modules not yet loaded.)
:display:gsg:glgsg(warning): BlendEquation advertised as supported by OpenGL runtime, but could not get pointers to extension function.
:display:gsg:glgsg(warning): BlendColor advertised as supported by OpenGL runtime, but could not get pointers to extension function.
:util(warning): Adjusting global clock’s real time by 0.223544 seconds.
DirectStart: Starting the game.
Warning: DirectNotify: category ‘Interval’ already exists
Traceback (most recent call last):
File “C:\Chaneciya\Main.py”, line 217, in ?
GAME = Game()
File “C:\Chaneciya\Main.py”, line 202, in init
self.accept(‘EC-into-Terrain’,self.PLAYER.Land())
File “C:\Panda3D-1.4.1\direct\src\showbase\DirectObject.py”, line 24, in accept
return messenger.accept(event, self, method, extraArgs, 1)
File “C:\Panda3D-1.4.1\direct\src\showbase\Messenger.py”, line 62, in accept
assert callable(method), (
AssertionError: method not callable in accept (ignoring): None
Process “Panda Python” terminated, ExitCode: 00000001
Has anyone got any suggestions?
Azraiyl
September 23, 2007, 10:47am
2
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
BoZ
September 23, 2007, 10:51am
3
Thanks for the quick reply, thats lead me to a different error.
Commandline: ppython C:\Chaneciya\Main.py
Workingdirectory:
Timeout: 0 ms
Known pipe types:
wglGraphicsPipe
(3 aux display modules not yet loaded.)
:display:gsg:glgsg(warning): BlendEquation advertised as supported by OpenGL runtime, but could not get pointers to extension function.
:display:gsg:glgsg(warning): BlendColor advertised as supported by OpenGL runtime, but could not get pointers to extension function.
:util(warning): Adjusting global clock’s real time by 0.218651 seconds.
:util(warning): Adjusting global clock’s real time by -0.637841 seconds.
DirectStart: Starting the game.
Warning: DirectNotify: category ‘Interval’ already exists
Traceback (most recent call last):
File “C:\Chaneciya\Main.py”, line 222, in ?
run()
File “C:\Panda3D-1.4.1\direct\src\showbase\ShowBase.py”, line 2176, in run
self.taskMgr.run()
File “C:\Panda3D-1.4.1\direct\src\task\Task.py”, line 930, in run
self.step()
File “C:\Panda3D-1.4.1\direct\src\task\Task.py”, line 862, in step
self.__stepThroughList(taskPriList)
File “C:\Panda3D-1.4.1\direct\src\task\Task.py”, line 764, in __stepThroughList
ret = self.__executeTask(task)
File “C:\Panda3D-1.4.1\direct\src\task\Task.py”, line 684, in __executeTask
ret = task(task.extraArgs)
File “C:\Panda3D-1.4.1\direct\src\showbase\EventManager.py”, line 47, in eventLoopTask
self.doEvents()
File “C:\Panda3D-1.4.1\direct\src\showbase\EventManager.py”, line 41, in doEvents
self.processEvent(self.eventQueue.dequeueEvent())
File “C:\Panda3D-1.4.1\direct\src\showbase\EventManager.py”, line 98, in processEvent
messenger.send(eventName, paramList)
File “C:\Panda3D-1.4.1\direct\src\showbase\Messenger.py”, line 240, in send
method ( (extraArgs + sentArgs))
TypeError: Land() takes exactly 1 argument (2 given)
Process “Panda Python” terminated, ExitCode: 00000001
This is my “Land” method.
def Land(self):
self.Standing = 1
BoZ
September 23, 2007, 10:59am
4
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! :D:D
Legion
September 23, 2007, 2:50pm
5
…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...
Azraiyl
September 23, 2007, 10:30pm
6
“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.