moving an object

ok,

I done it with cmd and i got this error:

File "ssss.py", line 35
  def vooruit(self):
                        ^
IndentationError: unindent does not match any outer indentation level

[/code]

srry,

^ has to been beneeth (self):

@oft: please def. efficient :slight_smile:

so please pro-soft, i have no time to play with you.
maybe this brings you in a good mood, i really think that you been a good coder.

there are 2 spaces before ‘def init’ and then another two spaces before ‘self.accept(‘arrow_up’,self.vooruit)’

then there one space before ‘def vooruit(self):’ and four spaces before print ‘vooruit!’

I think the problem is that your not being consistent with spaces, python is sensitive to this! I recommend using tabs (I know, you can’t use tabs on the forum) at least use tabs in your code. And when copy-pasting code, check to make sure the indentation is the same, or use SHIFT-TAB untill the lines have no leading spaces, and then TAB to add the correct number of spaces

also, to save the output of a program to a file (if command prompt closes to quickly, or if it’s just more convenient) use ‘1>outputfile’ and/or ‘2>errorfile’.

ppython main.py 1>output.txt 2>errors.txt

There is an error if you use the same file for ‘1>’ and ‘2>’, so don’t

tanx again for you replys,

but how abaout my script?

if i use the code

base.cam.setPos(base.cam,-1,0,0)

in a task, it will run every frame, what is not nessassary.

(sorry for my bad englisch, i am belgium you now…)

greets and tanx for your help.

with a if statement, something like this…

class MyClass(DirectObject):
    '''
    classdocs
    '''
    def __init__(self):
        '''
        Constructor
        '''
        self.keys = {"vaenster":0}
        self.accept("arrow_left", self.key,["vaenster",1])
        self.accept("arrow_left-up", self.key,["vaenster",0])

        taskMgr.add(self.move,"move")
        
    def key(self,i,value):
        self.keys[i] = value
    
    def move(self,task):
        if(self.keys["vaenster"]!=0):
            #put your code in here
            base.camera.setH(base.camera.getH()+1)
        return task.cont
        
m=MyClass()
run()

all that code you posted earlier, what exactly are you trying to do with it? You shouldn’t be calling taskMgr.add more than once per subroutine in normal circumstances

yo,

i just wanted to create a basic game (as i am new to panda), pressing to arrow keys wil move the camera and at the same time a car.

I know its simple for you, but i want to learn panda in steps.

So if anyone of you has some tips for me to learn panda3D,
give me them please, it is very welcom.

tanx and greets.

to move a car is pretty tricky, ok you could move it like a stone, but this wont feels good. so my tip: use something which reacts easier than a car.

Try this:

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *

#disable default camera controller
base.disableMouse()
#create an event listener object
eventListener = DirectObject()

#load car model (use a unit cube (1by1by1) or similar in size)
car = loader.loadModel("cube")
assert not car.isEmpty(), "cannot find car file"
car.reparentTo(render)

#setup camera (if you uncomment the next line, make sure to use some terrain)
##camera.reparentTo(car)    #uncomment to move camera with car
camera.setPos(0, -10, 3)
camera.lookAt(car)

#variables
wheelRot = 0
#constants
speed = 1
sensitivity = 1

def moveCar(amount):
    car.setH(car, wheelRot)
    car.setY(car, amount)
	
def turnWheels(amount):
    global wheelRot
    wheelRot += amount

#setup event handlers
eventListener.accept("w", moveCar, [speed])
eventListener.accept("w-repeat", moveCar, [speed])

eventListener.accept("s", moveCar, [-speed])
eventListener.accept("s-repeat", moveCar, [-speed])

eventListener.accept("a", turnWheels, [sensitivity])
eventListener.accept("a-repeat", turnWheels, [sensitivity])

eventListener.accept("d", turnWheels, [-sensitivity])
eventListener.accept("d-repeat", turnWheels, [-sensitivity])

#run!
run()