First get this to work and then I’ll help you with a pop-up menu. (Sorry would write some code for you, but really don’t have a lot of time, even thos it’s my b-day today ^^.)
First, look up something called task, and learn how they work:
panda3d.org/manual/index.php/L … anda_Model
panda3d.org/manual/index.php/Tasks
Then make sure you have this code listed below:
panda3d.org/manual/index.php/C … 3D_Objects
Now we then assian it to a key:
panda3d.org/manual/index.php/Keyboard_Support
Example on how this would look ish (so don’t use it lol):
def Controls(self):
#Defindes our keymap
self.keyMap = {"menu":0, "left":0, "right":0, "forward":0, "back":0, "jump":0, "shoot":0}
#Accept the control keys for movement
self.accept("escape", self.setKey, ["menu",1])
self.accept("a", self.setKey, ["left",1])
self.accept("d", self.setKey, ["right",1])
self.accept("w", self.setKey, ["forward",1])
self.accept("s", self.setKey, ["back",1])
self.accept("space", self.setKey, ["jump",1])
self.accept("mouse1", self.setKey, ["shoot",1])
self.accept("escape-up", self.setKey, ["menu",0])
self.accept("a-up", self.setKey, ["left",0])
self.accept("d-up", self.setKey, ["right",0])
self.accept("w-up", self.setKey, ["forward",0])
self.accept("s-up", self.setKey, ["back",0])
self.accept("space-up", self.setKey, ["jump",0])
self.accept("mouse1-up", self.setKey, ["shoot",0])
After we have everything this far. Lets put it all togather. After you make the example code above, add a task command to check for those keys. Usally people call this a “controls” task. As you learn and use the task command you’ll start to see the power behind them.
Example of this:
#Controls for moving around.
taskMgr.add(self.move,"moveTask")
After we set that up, we have to now setup a def name move and make it a task by definding that in the (). We can also add our if/check and to make life easy and since we all ready def the code to shoot, we just make a “hot link” to our predefinde code.:
def move(self, task):
if (self.keyMap["shoot"]!=0):
self.myFunction()
or do it the long way:
def move(self, task):
if (self.keyMap["shoot"]!=0):
mpos=base.mouseWatcherNode.getMouse()
pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())
myTraverser.traverse(render)
#assume for simplicity's sake that myHandler is a CollisionHandlerQueue
if myHandler.getNumEntries() > 0:
myHandler.sortEntries() #this is so we get the closest object
pickedObj=myHandler.getEntry(0).getIntoNodePath()
pickedObj=pickedObj.findNetTag('myObjectTag')
if not pickedObj.isEmpty():
handlePickedObject(pickedObj)