Hello David,
I didn’t run your code (don’t have the models anyway), but from what I see your “hand” model will stay in one place. Let me try to explain why.
right = None
def increment():
global right
right=0
right=right+1
return right
def left(task):
control.setP(right)
return Task.cont
increment()
taskMgr.add(left, "left")
run()
I focus on just this part of your code, since it is where you “control” your scene. This is what happens when you run the code, step by step:
First, “None” gets assigned to the variable “right”. Fine.
Next you define a method “increment”. The method is only defined, it isn’t called yet. So nothing happens.
Next you define another method, “left”. It is defined as a Panda3D task, but not yet added to the task managed, so again nothing happens until now.
Now you call “increment( )” once. The method defines a global variable “right”, that means assigning a value to “right” will change the variable not only in local namespace.
Let’s have a closer look at the internals of method “left”:
- You assign 0 to the variable “right”. Now “right” has the value “0”. Every time you call the method, no matter what right has been before.
- You assign “right + 1” to the varibale “right”. since “right” has been “0” before it is now “1”.
- You return the variable “right”. Useless, since the return value is discarded. To use a return value you would have to call the method like this: “foo = increment( )”.
So, in total, after calling “increment( )” your variable “right” is always 1, no matter how often you call “increment”
Just using “right = 1” would have the same effect.
On to the next line. You add the method “left” to the task manager. This means once the game is running the method “left” will be called by Panda3D once a frame. But it is not yet running.
Last line: you enter the game main loop by calling “run( )”. So from now on the method “left” will be called once a frame.
Ok, what happens from now on? Each frame “left” gets called.
Let’s have a look at the what exactly the method “left” does:
It sets the Pitch § to the value “right”. And “right” is 1. So each frame the pitch of “control” is set to 1 (degree). Pitch is the angle your models “nose” points up or down, if it was an aircraft.
So, no code to move the model sideways/left, only code to set it’s orientation. And the task will always set the same orientation, so it will stay where it is and look in the same direction forever.
Let me suggest some code to replace all of the above lines:
def left(task):
control.setX( control.getX( ) + 1 )
return Task.cont
taskMgr.add(left, "left")
run()
Just a warning: This means once a frame the model “control” is translated by 1 sideways. At 60fps this makes a translation of 60 per second. At 600 fps (simple scene, so possible on current hardward) this means 600 per second. To be able to see the movement you should use a smaller value, perhaps 0.02.
Hope this helps to get you started.
enn0x