I am trying to make a space sim in python 2.5 and panda3d 1.7.2
I have the ship loaded, and the key map is set up. The controls even work (the ones that ive made so far, I haven’t bothered with some as I’m still just trying things out and i want to keep my tests on a smaller scale). What I want to do now is have the ship model, not the root node that I defined, and to which everything is parented, to rotate up based on the amount of time you have been pressing the “w” key, and then rotate back to a base position based on the amount of time that has passed since you let go. I don’t understand why my code isn’t working. Could someone please lead me in the right direction on this?
Sorry, I realize this is kind of simple, but I’m new to programming in general.
Here’s the code:
def shipControl(self, task):
dt = globalClock.getDt()
self.root.setY(self.root, self.throttle * self.maxSpeed * dt)
if (self.keyMap.keyMap["w"] == True):
if self.throttle != 0:
self.root.setP(self.root, self.handling * dt)
elif self.throttle == 0:
self.root.setP(self.root, (self.handling * dt))
elif (self.keyMap.keyMap["s"] == True):
if self.throttle != 0:
self.root.setP(self.root, (-1 * self.handling * dt))
elif self.throttle == 0:
self.root.setP(self.root, -1 * (self.handling * dt))
if (self.keyMap.keyMap["arrow_up"] == True):
if self.throttle < 1:
self.throttle += .05 * dt
elif self.throttle >= 1:
self.throttle = 1
print self.throttle
if (self.keyMap.keyMap["arrow_down"] == True):
self.throttle -= .05 * dt
print self.throttle
modelRotation(task.time)
return task.cont
def modelRotation(self, time):
if (self.keyMap.keyMap["w"] == True):
self.shipModel.setP(time * -5)
elif (self.keyMap.keyMap["s"] == True):
self.shipModel.setP(time * 5)
else:
if (self.keyMap.keyMap["w"] == False) and (self.keyMap.keyMap["s"] == False):
if self.shipModel.getP() > 0:
self.shipModel.setP(time * -5)
else:
self.shipModel.setP(time * 5)
Any help is greatly appreciated,
Thanks
Peter
[/code]