moving an object


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


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
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
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.


im very curious which thing we will see at you at last :wink:

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


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


#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")
m = loader.loadModel("teapot")

def potjemee(task):
    return Task.cont

class Hello(DirectObject.DirectObject):
  def __init__(self):
 def vooruit(self):
     print 'vooruit!'
     taskMgr.add(potjemee, "potjemeet"),0,1,0)
 def links(self):
     print 'links!'
     taskMgr.add(potjemee, "potjemeet"),-1,0,0)

 def rechts(self):
       print 'rechts!'
 def achteruit(self):
       print 'achteruit!'
h = Hello()


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. … ur_Program

@cheburashka: true, but this works :wink: sorry


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 :wink:

i would never use a direct way to move a model, but trust me this works :wink:

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 :wink: feel free to press z twice :wink:

obj = loader.loadModel("models/planeZ")
class MyClass(DirectObject):

    def __init__(self):
    def move (self,task):
        return task.cont

@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 :wink: 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.