hello,
I have another question. I am kind new to panda so dont be mad if this is a stupid question.
I just want to know how i can move a object…
i am familiar with BASIC-codes, but in python that doesnt work…
need help, thanx
greets
hello,
I have another question. I am kind new to panda so dont be mad if this is a stupid question.
I just want to know how i can move a object…
i am familiar with BASIC-codes, but in python that doesnt work…
need help, thanx
greets
the samples help a lot when learning panda3d, the solar system samples will probably be the easiest on this topic.
things you need to look at (and read!):
the scene graph panda3d.org/manual/index.php/The_Scene_Graph
loading models panda3d.org/manual/index.php/Loading_Models
Yeah check out the samples…
You might also want to read the beginning of the manual…
it teaches you to move things with intervals
I don’t know if I should be giving away the answer like this (seeing as nobody else has) but to set a object’s position (assuming your object is a NodePath), just use
object.setPos(xPosition, yPosition, zPosition)
or to move an object, use
object.setPos(object, xMovement, yMovement, zMovement)
tanx for your replys,
but this isnt what i am looking for.
the position must be automaticly changed:
when you press z position (y) must be +1.
what about this?
yes this works. just obj.setY(obj.getY()+1) .
take a look on this discourse.panda3d.org/viewtopic.php?t=6842
it should help you with…
Read up on keyboard event handlers. Then contemplate how setPos/setX/setY/setZ might be combined therewith. It’s not too tricky if you’ve read the first few chapters of the manual and gotten a sense of how Panda runs in general.
yes its quiet easy.
accept("z",obj.setY(obj.getY()+1)
im very curious which thing we will see at you at last
that won’t work because the definition of accept is:
DirectObject.accept(self, event, method, extraArgs=[])
so python will call ‘setY’ and pass it’s return value to ‘accept’, which is None, so when ‘accept’ calls ‘method’ it will fail.
try using:
eventListener = DirectObject()
eventListener.accept("z", NodePath.setPos, [obj, obj, 0, 1, 0])
that way, DirectObject will do the following when you press the z key:
obj.setPos(obj, 0, 1, 0) #moves 1 unit along the y axis
tanx,
In the evening i “playd” python again and i came to this result.
first run, second run , third run… everithing goes fine.
but several minutes later, i run it again… just cmd and then it closes…
it happend before, so i realy need help…
whats wrong with this code?:
import direct.directbase.DirectStart
from direct.showbase import DirectObject
from direct.task import Task
import math
base.useDrive()
#With DirectObject loaded, it is possible to create a subclass of DirectObject.
#This allows the class to inherit the messaging API and thus listen for events.
#The sample below creates a class that can listen for events.
#The "accept" function notifies panda that the printHello method is an event handler for the mouse1 event.
#The "accept" function and the various event names will be explained in detail later.
environ = loader.loadModel("map")
environ.reparentTo(render)
m = loader.loadModel("teapot")
m.reparentTo(render)
def potjemee(task):
m.setPos(base.cam,0,8,-2)
m.setH(base.cam,0)
return Task.cont
class Hello(DirectObject.DirectObject):
def __init__(self):
self.accept('arrow_up',self.vooruit)
self.accept('arrow_up-repeat',self.vooruit)
self.accept('arrow_left',self.links)
self.accept('arrow_left-repeat',self.links)
self.accept('arrow_right',self.rechts)
self.accept('arrow_right-repeat',self.rechts)
self.accept('arrow_down',self.achteruit)
self.accept('arrow_down-repeat',self.achteruit)
def vooruit(self):
print 'vooruit!'
taskMgr.add(potjemee, "potjemeet")
base.cam.setPos(base.cam,0,1,0)
def links(self):
print 'links!'
taskMgr.add(potjemee, "potjemeet")
base.cam.setPos(base.cam,-1,0,0)
def rechts(self):
print 'rechts!'
m.setPos(base.cam,0,8,-2)
m.setH(base.cam,0)
base.cam.setPos(base.cam,1,0,0)
def achteruit(self):
print 'achteruit!'
m.setPos(base.cam,0,8,-2)
m.setH(base.cam,0)
base.cam.setPos(base.cam,0,-1,0)
h = Hello()
run()
MOD EDIT: Please use code tags next time… I’ve added them for you this time.
Well, if you run your game via cmd, what error message appears?
i cant see it…
cmd appears only 1/24 second.
i tried to film it with camstudio, but text in cmd does show…
Run your game in cmd, then it will stay open when an error occurs.
ditus, Not quite. That will evaluate obj.getY() at the point where the event is defined, not where it is invoked.
Try pressing z twice - it won’t move after the first time.
This works, though:
base.accept("z", lambda: obj.setY(obj.getY() + 1))
just let it run in a task
i would never use a direct way to move a model, but trust me this works
Surely you can put the accept in a task, but that’s the most crazy and inefficient way to setup a handler to move an object I’ve ever heard.
look feel free to press z twice
obj = loader.loadModel("models/planeZ")
obj.setPos(0,10,0)
obj.reparentTo(render)
class MyClass(DirectObject):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
taskMgr.add(self.move,"move")
def move (self,task):
self.accept("z",obj.setZ,[obj.getZ()+1])
return task.cont
m=MyClass()
run()
@poor-soft: im sorry that you heard not much in live. so if i count the characters, it seems to be very efficient to me but like i said before, im not using this way. it only moves your model.
so relaxe.
How old are you ditus, if I may ask?
Just curious.
PS. “efficient” has nothing to do with the code’s character count.