So I’m trying to piece together keyboard input. My goal is to move a robot I’ve built forwards, along the Y axis. However, my current code returns an error when I try to run it;
Here’s my code so far:
from math import pi, sin, cos
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import Sequence
from pandac.PandaModules import Point3
import sys #used for Esc = Quit command
#create Charles's location in variables
charlesY = 5.0
class MyApp(ShowBase):
def KeyInput(self):
#Handle keyboard input
self.accept('escape', sys.exit) #Exit the program when the Esc key is pressed
#&&&ERROR
self.accept('w', self.moveCharlesForward()) #move Charles forward
return
def moveCharlesForward(self):
global charlesY
charlesY += .5
return
def __init__(self):
#Create a function to move charles forward
ShowBase.__init__(self)
#load the small room (orientation = spawn camera)
#textures
self.groundTexture = self.loader.loadTexture("myWork/myTextures/groundTexture.bmp")
self.wallTexture = self.loader.loadTexture("myWork/myTextures/wallTexture.bmp")
self.wallTexture2 = self.loader.loadTexture("myWork/myTextures/wallTexture2.bmp")
self.charlesTexture = self.loader.loadTexture("myWork/myTextures/charlesTexture.jpg")
#ground
self.groundOrig = self.loader.loadModel("myWork/myModels/ground")
self.groundOrig.reparentTo(self.render)
self.groundOrig.setScale(0.25, 0.25, 0.25)
self.groundOrig.setPos(0, 5, -1)
self.groundOrig.setTexture(self.groundTexture)
#left wall
self.wallL1 = self.loader.loadModel("myWork/myModels/wall")
self.wallL1.reparentTo(self.render)
self.wallL1.setScale(0.25, 0.25, 0.25)
self.wallL1.setPos(-2.2, 5.25, 0.01)
self.wallL1.setTexture(self.wallTexture)
#right wall
self.wallR1 = self.loader.loadModel("myWork/myModels/wall")
self.wallR1.reparentTo(self.render)
self.wallR1.setScale(0.25, 0.25, 0.25)
self.wallR1.setPos(2.2, 5.25, 0.01)
self.wallR1.setTexture(self.wallTexture)
#back wall
self.wallB = self.loader.loadModel("myWork/myModels/wall2")
self.wallB.reparentTo(self.render)
self.wallB.setScale(0.25, 0.25, 0.25)
self.wallB.setPos(0, 7, 0)
self.wallB.setTexture(self.wallTexture2)
#load the player
#load Charles, the robot
self.charles = self.loader.loadModel("myWork/myModels/charles")
self.charles.reparentTo(self.render)
self.charles.setScale(0.25, 0.25, 0.25)
self.charles.setPos(0, charlesY, -.4)
self.charles.setTexture(self.charlesTexture)
self.KeyInput()
app = MyApp()
app.run()
Any help would be greatly appreciated.