moveing my character

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):,self.ralph.getY()-30,self.ralph.getZ()+10)

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
		if (bla == "backward"):
			self.ralph.setY(self.ralph.getY()-1)		self.ralph.setZ(self.root,self.terrain.getElevation(self.ralph.getX(),self.ralph.getY()))			
		if(bla == "left"):			self.ralph.setZ(self.root,self.terrain.getElevation(self.ralph.getX(),self.ralph.getY()))			self.ralph.setH(self.ralph.getH()+2)								

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?


When doing this:


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

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):,self.ralph.getY()-30,self.ralph.getZ()+10) 


def ralphcam(self):,30),10)

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

Almost. :slight_smile:
Something like this:, 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 :smiley:

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

ps: great avatar :wink:

Yeah, that’s possible using something like this:

class YourWorldClass:
  def __init__(self):
    ... some stuff here ...
    self.text = OnscreenText(blah blah, mayChange = True)
    base.taskMgr.add(self.updateText, "OnscreenText ralph position")
    ... more stuff here ...
  def updateText(self, task):
    self.text.setText("Ralph: %d,%d,%d" % (self.ralph[0], self.ralph[1], self.ralph[2]))
    return task.cont

Hello again,
make my camera moving by mouse is quite harder i’d thougt :stuck_out_tongue:

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 =
			y = 
			if ( < screenCenterX):,1)
			if ( > screenCenterX):,-1)
			if ( < screenCenterY):,1)	
			if ( > screenCenterY):,-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 :wink:

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?


PS: i´m using Geomip-terrain :wink:

For a simple flat colored sky, set the clear color of the window to the color you want the sky to be, eg,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 :wink:

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 :wink:
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.currCamX =
		self.currCamY =
		self.CharCamX = 0
		self.CharCamY = 30
		self.CharCamZ = 12
	def defaultCam(self,char):,self.CharCamX,self.CharCamY,self.CharCamZ)
		#print "CamPos: " + str(self.CharCamX) + " - " + str(self.CharCamY)  + " - " + str(self.CharCamZ)
		###Function to set up Mouse Rotation###
	def setMouseView(self,task):
		###center mouse###,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() -
			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
		return task.cont
		###Functions to enable/disable Mouse"grep" Tasks for Rotation###
	def setMouseViewTask(self):
		taskMgr.add(self.setMouseView, "setMouseView")
	def removeMouseViewTask(self):

and the movement part:

	####key settings###
def setKey(action,value):
	isMoveing[action] = value
	if (isMoveing["forward"] or isMoveing["backward"])  : 
	if not (isMoveing["forward"] or isMoveing["backward"]):
	return isMoveing

def move(isMoveing,task):
 	if isMoveing["forward"]: 
		MainChar.setZ(terrain.getRoot(),terrain.getElevation(MainChar.getX(),MainChar.getY()))	#set Y coord -2 to actor...move	im forward
	if isMoveing["backward"]:
	if isMoveing["turnleft"]:
	if isMoveing["turnright"]:
	return Task.cont		
taskMgr.add(move , "moveTask" , extraArgs=[isMoveing , Task] )

best regards,

push :smiley: