Override default arrow key commands


My first post in Panda !!

I am attempting to override the default arrow keys with my own methods, it appears to work for a second than goes to default. More specifically I want the camera to move 360 degrees with the arrow keys. I set up defs to do this and when i press the arrow up key to aim camera up, the angle of the camera moves for a second, but then program jolts out of this and moves the point of view forward, which was the old command I was trying to override.

Here’s a small sample of code;

self.accept(“arrow_up”, self.lookUp, [1])

def lookUp(self, direction):
self.angle += direction*1.0
base.camera.setHpr(0, self.angle, 0)


Hello Gary,

I had these kinds of errors several times and they are related to the way you typed your code. Most of the time, they are due because of involonteared mistakes… It will be diffucult to answer your question without seeing the whole code but you can try to debug using some:

print myVar #before entering your function
print myVar #at the middle of your function
print myVar #at the end.
print #just for separating the output

This can be very handy to understand what’s your function is doing and where the problem is coming from.

Good luck :wink:

a single key can activate more than one function

self.accept('arrow-up', foo)
self.accept('arrow-up, bar)

will result of ‘arrow’ up doing both foo and bar.

I think you’re looking at something like ‘ignore’:

self.accept('arrow-up', foo)

Have you perhaps somewhere called base.useDrive(), or not called base.disableMouse(), the latter to disable the default camera behaviour?

(I’m afraid that I’m not sure offhand of whether the keyboard control is on by default, or whether it is a manual call to useDrive() that does it.)

Thanks all.

It was a combination of using base.drive(), as Thaumaturge wrote, and resetting HPR values unintentionally. Turns out i should have just changed each value independently, such as:

self.angle += camspeed

to angle the camera upwards and avoid changing parameters that did not need changing.