heyho,
i want to move my character in me world, forward and backward works fine but if i want to move to left or right something is wrong with my code…
#function to set camera to ralph's 3rd person perspective
def ralphcam(self):
base.camera.setPos(self.ralph.getX(),self.ralph.getY()-30,self.ralph.getZ()+10)
#base.camera.setH(self.ralph.getH())
base.camera.setP(-5)
def move(self,bla):
if (bla == "forward"):
self.ralph.setY(self.ralph.getY()+1) self.ralph.setZ(self.root,self.terrain.getElevation(self.ralph.getX(),self.ralph.getY()))
##set cam to ralph's 3rd person
self.ralphcam()
Task.cont
if (bla == "backward"):
self.ralph.setY(self.ralph.getY()-1) self.ralph.setZ(self.root,self.terrain.getElevation(self.ralph.getX(),self.ralph.getY()))
self.ralphcam()
Task.cont
if(bla == "left"): self.ralph.setZ(self.root,self.terrain.getElevation(self.ralph.getX(),self.ralph.getY())) self.ralph.setH(self.ralph.getH()+2)
self.ralphcam()
Task.cont
if i push a for turn left, ralph turns left, then pushing w to walk forward, ralph walks forward (into the monitor), but he should walk to left…where he is looking at.
how can i make ralph walking to this direction he is looking at?
Hello again,
make my camera moving by mouse is quite harder i’d thougt
the camera rotates if i am moveing the mouse, but all off the center of the window.
if my mouse is in the upper part of the window and i push it down, the cam “walks” up until the mouse passes the “horizental middleline” of the window, the “walks” down.
this is my code:
if self.keys["mousecam"]:
x = base.win.getPointer(0).getX()
y = base.win.getPointer(0).getY()
if (base.win.getPointer(0).getX() < screenCenterX):
base.camera.setH(base.camera,1)
if (base.win.getPointer(0).getX() > screenCenterX):
base.camera.setH(base.camera,-1)
if (base.win.getPointer(0).getY() < screenCenterY):
base.camera.setP(base.camera,1)
if (base.win.getPointer(0).getY() > screenCenterY):
base.camera.setP(base.camera,-1)
self.text3.setText("Mouseposition(changed): %d, %d" % (x,y))
I had trouble with the camera too, some task moves the camera automatically if you don’t disable it. Finally I got it working, maybe it helps if you have a look at this thread
Hello again,
after some weeks stop programming, i found back to panda and my little game
i´m searching the forum, manual and reference, but don´t find something about sky. what do i need to set a sky in the background of my game and how can a set it?
Note that Panda doesn’t provide any special interface to create a sky. It doesn’t need one. Just create a dome big enough to hold your universe and put it in the scene. There are also fancier ways to create a sky, but this is the easiest to understand.
Hello again,
now i have a very “strange” problem
my Plan: moving my char, change camview by pressing rightmouse and move.
this ist working fine. but if i move my char again (pressing wasd-keys) the “camview” is set up to the “default” values i’d specified. why? an what can i do to get the mouseview saved during walking around?
here’s my control class:
class Character(DirectObject):
###Class for the MainCharacter. Includes Control and .... uhm nothing^^
def __init__(self):
self.getMousePosX={"last":0,"current":0}
self.getMousePosY={"last":0,"current":0}
self.currCamX = base.cam.getX()
self.currCamY = base.cam.getY()
self.CharCamX = 0
self.CharCamY = 30
self.CharCamZ = 12
def defaultCam(self,char):
base.cam.setPos(char,self.CharCamX,self.CharCamY,self.CharCamZ)
base.cam.lookAt(char)
#print "CamPos: " + str(self.CharCamX) + " - " + str(self.CharCamY) + " - " + str(self.CharCamZ)
#base.cam.reparentTo(char)
###Function to set up Mouse Rotation###
def setMouseView(self,task):
###center mouse###
x=base.win.getProperties().getXSize()/2
y=base.win.getProperties().getYSize()/2
base.win.movePointer(0,x,y)
if base.mouseWatcherNode.hasMouse():
#self.getMousePosX["last"] = self.getMousePosX["current"]
#self.getMousePosY["last"] = self.getMousePosY["current"]
self.getMousePosX["current"] = base.mouseWatcherNode.getMouseX()
self.getMousePosY["current"] = base.mouseWatcherNode.getMouseY()
CamDistX = MainChar.getX() - base.cam.getX()
print CamDistX
if (self.getMousePosY["current"] < 0):
#Mouse moves down, looking down
self.CharCamZ = self.CharCamZ + 1
if (self.getMousePosY["current"] > 0):
#Mouse moves up, looking up
self.CharCamZ = self.CharCamZ - 1
if (self.getMousePosX["current"] < 0):
#Mouse moves left
if not (CamDistX > 10 or CamDistX < -10):
self.CharCamX = self.CharCamX - 3
if (self.getMousePosX["current"] > 0):
#Mouse moves right
if not (CamDistX > 10 or CamDistX < -10):
self.CharCamX = self.CharCamX + 3
self.defaultCam(MainChar)
return task.cont
###Functions to enable/disable Mouse"grep" Tasks for Rotation###
def setMouseViewTask(self):
taskMgr.add(self.setMouseView, "setMouseView")
def removeMouseViewTask(self):
taskMgr.remove("setMouseView")
and the movement part:
####key settings###
def setKey(action,value):
isMoveing[action] = value
if (isMoveing["forward"] or isMoveing["backward"]) :
MainChar.loop("walk")
if not (isMoveing["forward"] or isMoveing["backward"]):
MainChar.stop()
return isMoveing
...
###Moveing
def move(isMoveing,task):
if isMoveing["forward"]:
MainChar.setY(MainChar,-.8)
MainChar.setZ(terrain.getRoot(),terrain.getElevation(MainChar.getX(),MainChar.getY())) #set Y coord -2 to actor...move im forward
Character().defaultCam(MainChar)
if isMoveing["backward"]:
MainChar.setY(MainChar,.8)
MainChar.setZ(terrain.getRoot(),terrain.getElevation(MainChar.getX(),MainChar.getY()))
Character().defaultCam(MainChar)
if isMoveing["turnleft"]:
MainChar.setH(MainChar,3)
if isMoveing["turnright"]:
MainChar.setH(MainChar,-3)
return Task.cont
taskMgr.add(move , "moveTask" , extraArgs=[isMoveing , Task] )