# moveing my character

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()

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()

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()

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?

regards
borat

When doing this:

``self.ralph.setY(self.ralph.getY()+1)  ``

You are setting ralph’s Y position relative to the world. To actually move him relative to himself (so in his own coordinate system), you should do:

``self.ralph.setY(self.ralph, 1)  ``

wow, really easy

thanks, is there a easy way to set the camera position to ralphÂ´s “3rd person” when ralph is turning?

something like changing this:

``````def ralphcam(self):
base.camera.setPos(self.ralph.getX(),self.ralph.getY()-30,self.ralph.getZ()+10)
base.camera.setP(-5) ``````

to:

``````def ralphcam(self):

base.camera.setX(self.ralph.getX())
base.camera.setY(self.ralph,30)
base.camera.setZ(self.ralph,10)
base.camera.setP(-5)``````

sorry, iÂ´m not at my computer atm so i canÂ´t test

Almost.
Something like this:

``base.camera.setPos(self.ralph, 0, -30, 10)``

(Note that doing a setPos is faster than setting them individually.)

horray, the cam is turning with ralph \o/
big thanks pro-rsoft.

the next days iÂ´ll try to move the cam by pushing and moveing the mouse, this should be a little bit harder but Mr. Boardsearch is my friend

btw. is there a way to draw ralphs current position (x,y,z) somewhere on the screen? maybe with a “onscreentext” ?

ps: great avatar

Yeah, that’s possible using something like this:

``````class YourWorldClass:
def __init__(self):
... some stuff here ...
self.text = OnscreenText(blah blah, mayChange = True)
... more stuff here ...

self.text.setText("Ralph: %d,%d,%d" % (self.ralph[0], self.ralph[1], self.ralph[2]))

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))
``````

how can i fix the mousecam script?

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?

Chris

PS: iÂ´m using Geomip-terrain

For a simple flat colored sky, set the clear color of the window to the color you want the sky to be, eg

``base.win.setClearColor(VBase4(0.0,0.0,1.0,1.0))``

For more advanced skies, with clouds, stars, the sun etc, you may want to look into sky boxes and sky domes. Google is your friend

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.

David

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###
###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)

###Functions to enable/disable Mouse"grep" Tasks for Rotation###
``````

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