"Third person shooter style" Roaming Ralph

Hi!
It’s my first steps in learning Panda3d and Python. It based based on FPS_camera_template code, if i found with this forum and of corse on Roaming Ralph tutorial. Thanks for authors.
With WASD keys and mouse you can control Ralph himself and TPS camera. Waiting for critic and/or advises. Das anybody has an idea how i can make Ralph jumping?
Here is code:

from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "show-frame-rate-meter 1") 
from pandac.PandaModules import CollisionTraverser,CollisionNode
from pandac.PandaModules import CollisionHandlerQueue,CollisionRay
from pandac.PandaModules import WindowProperties
from direct.showbase.DirectObject import DirectObject # To listen for Events
from direct.task import Task # To use Tasks 
from direct.actor.Actor import Actor
from pandac.PandaModules import Vec3,Vec4,BitMask32
from direct.gui.OnscreenText import OnscreenText
import direct.directbase.DirectStart
from pandac.PandaModules import ConfigVariableString 
import sys, os, math
from pandac.PandaModules import Filename
from pandac.PandaModules import PandaNode,NodePath,Camera,TextNode
from direct.gui.OnscreenText import OnscreenText
from direct.task.Task import Task

MYDIR=os.path.abspath(sys.path[0])
MYDIR=Filename.fromOsSpecific(MYDIR).getFullpath()

# Function to put instructions on the screen.
def addInstructions(pos, msg):
    return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
			pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)

# Function to put title on the screen.
def addTitle(text):
    return OnscreenText(text=text, style=1, fg=(1,1,1,1),
	                pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)
                        
class World(DirectObject):
  def __init__(self):
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)
	base.setBackgroundColor(0, 0, 0)    
	base.disableMouse()                 
	camera.setPos ( 0, 0, 20 )          
	camera.setHpr ( 0, 0, 0 )
	self.heading = 180
	self.pitch = 0	
        
        self.title = addTitle("Third person shooter template")
        self.inst1 = addInstructions(0.95, "[ESC]: Quit")
        self.inst2 = addInstructions(0.90, "[A]: Strafe Left")
        self.inst3 = addInstructions(0.85, "[D]: Strafe Right")
        self.inst4 = addInstructions(0.80, "[W]: Run Forward")
        self.inst6 = addInstructions(0.75, "[S]: Run backward")
        self.inst7 = addInstructions(0.65, "[Shift]: Acceleration")
        self.inst7 = addInstructions(0.55, "[Mouse]: Camera control")
        
	self.keys = {"strafeLeft" : 0, "strafeRight": 0,
				 "accel": 0, "back": 0, "jump": 0, "run": 0}

	self.accept("escape", sys.exit)            #Escape quits
	#Other keys events set the appropriate value in our key dictionary
	self.accept("a",     self.setKey, ["strafeLeft", 1])
	self.accept("a-up",  self.setKey, ["strafeLeft", 0])
	self.accept("d",    self.setKey, ["strafeRight", 1])
	self.accept("d-up", self.setKey, ["strafeRight", 0])
	self.accept("w",       self.setKey, ["accel", 1])
	self.accept("w-up",    self.setKey, ["accel", 0])
	self.accept("s",       self.setKey, ["back", 1])
	self.accept("s-up",    self.setKey, ["back", 0])
	#self.accept("spacebar",       self.setKey, ["jump", 1])
	#self.accept("spacebar-up",    self.setKey, ["jump", 0])
	self.accept("shift",       self.setKey, ["run", 1])
	self.accept("shift-up",    self.setKey, ["run", 0])
	self.accept("shift-a",     self.setKey, ["strafeLeft", 1])
	self.accept("shift-a-up",  self.setKey, ["strafeLeft", 0])
	self.accept("shift-d",    self.setKey, ["strafeRight", 1])
	self.accept("shift-d-up", self.setKey, ["strafeRight", 0])
	self.accept("shift-w",       self.setKey, ["accel", 1])
	self.accept("shift-w-up",    self.setKey, ["accel", 0])
	self.accept("shift-s",       self.setKey, ["back", 1])
	self.accept("shift-s-up",    self.setKey, ["back", 0])
	self.gameTask = taskMgr.add(self.gameLoop, "gameLoop")
	self.gameTask.last = 0         
        self.isMoving = False
        self.environ = loader.loadModel("models/world")      
        self.environ.reparentTo(render)
        self.environ.setPos(0,0,0)
        self.environ.setScale(5,5,5)
        StartPos = self.environ.find("**/start_point").getPos()
	# create dummy cam to which the gun can be attached
	self.c_node = render.attachNewNode("camera_dummy_node") 
        self.ralph = Actor("models/ralph",
                                 {"run":"models/ralph-run",
                                  "walk":"models/ralph-walk"})                                  
        self.ralph.reparentTo(render)
        self.ralph.setScale(1.0)
        self.ralph.setHpr(0,0,0)	

	# Set angles
	self.c_node.setHpr(0, 0, 0)	  
	# Attach the camera to the dummy node. 
	camera.reparentTo(self.c_node)
        self.c_node.setPos(StartPos)
	self.ralph.setPos(StartPos)	
	# Position the camera 
	camera.setPosHpr(Vec3(0,-40,10),Vec3(0,0,0))
	self.prevtime = 0
        
        self.cTrav = CollisionTraverser()

        self.ralphGroundRay = CollisionRay()
        self.ralphGroundRay.setOrigin(0,0,1000)
        self.ralphGroundRay.setDirection(0,0,-1)
        self.ralphGroundCol = CollisionNode('ralphRay')
        self.ralphGroundCol.addSolid(self.ralphGroundRay)
        self.ralphGroundCol.setFromCollideMask(BitMask32.bit(0))
        self.ralphGroundCol.setIntoCollideMask(BitMask32.allOff())
        self.ralphGroundColNp = self.c_node.attachNewNode(self.ralphGroundCol)
        self.ralphGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler)
        
        # Uncomment this line to see the collision rays
        #self.ralphGroundColNp.show()
        #Uncomment this line to show a visual representation of the 
        #collisions occuring
        #self.cTrav.showCollisions(render)         
  def setKey(self, key, val):
	  self.keys[key] = val
  def gameLoop(self, task):
	self.elapsed = task.time - self.prevtime
        startpos = self.c_node.getPos()
	if self.keys["strafeLeft"]:
		self.strafe(-1)
	if self.keys["strafeRight"]:
		self.strafe(1)
	if self.keys["accel"]:
		self.walk(1)
	if self.keys["back"]:
		self.walk(-1)
	self.MouseTask()
	if self.keys["accel"] and self.keys["run"]:
		self.walk(2)
	if self.keys["back"] and self.keys["run"]:
		self.walk(-2)
        if self.keys["accel"] or self.keys["strafeLeft"] or self.keys["strafeRight"] or self.keys["back"]:
            if self.isMoving is False:
                self.ralph.loop("run")
                self.isMoving = True
        else:
            if self.isMoving:
                self.ralph.stop()
                self.ralph.pose("walk",5)
                self.isMoving = False
        self.cTrav.traverse(render)

        # Adjust camera dummy node Z coordinate.  If c_node ray hit terrain,
        # update his Z. If it hit anything else, or didn't hit anything, put
        # it back where he was last frame.

        entries = []
        for i in range(self.ralphGroundHandler.getNumEntries()):
            entry = self.ralphGroundHandler.getEntry(i)
            entries.append(entry)
        entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
                                     x.getSurfacePoint(render).getZ()))
        if (len(entries)>0) and (entries[0].getIntoNode().getName() == "terrain"):
            h = entries[0].getSurfacePoint(render).getZ()
            self.c_node.setZ(h)
            self.ralph.setZ(h)
        else:
            self.c_node.setPos(startpos)
            self.ralph.setPos(startpos)              
	self.MouseTask()		
	self.prevtime = task.time
	return Task.cont

  def strafe(self,dir):
	  elapsed = self.elapsed
	  strafe = self.c_node.getNetTransform().getMat().getRow3(0)
          strafe.setZ(0)
	  strafe.normalize()
          i = strafe*(elapsed*45*dir)
	  self.c_node.setPos(self.c_node.getPos() + i)
	  self.ralph.setPos(self.ralph.getPos() + i)
  def walk(self,speed):
	  elapsed = self.elapsed
	  forward = self.c_node.getNetTransform().getMat().getRow3(1)
	  forward.setZ(0)
	  forward.normalize()
          i = forward*(elapsed*45*speed)
	  self.c_node.setPos(self.c_node.getPos() + i)
	  self.ralph.setPos(self.ralph.getPos() + i)
  def MouseTask(self):
	  try:
		x = base.win.getPointer(0).getX()
		y = base.win.getPointer(0).getY()

		if base.win.movePointer(0, 100, 100):
				self.heading = self.heading - (x - 100)*0.2
				self.pitch = self.pitch - (y - 100)*0.2
		if (self.pitch < -45): self.pitch = -45
		if (self.pitch >  -3): self.pitch =  -3
		self.c_node.setHpr(self.heading,self.pitch,0)
                self.ralph.setH(self.heading +180)
	  except: pass


w = World()
run()

also files

P.S. Sorry for my bad english :blush:

The first way is to make the animation of jumping Ralph.
Also, I think you can use Intervals (explained in the manual, and in the “Hello World” tutorial). On “space” it will be activated, and will gradually adjust the Z position up and then down.

There are some problems:
If i make jump animation of Ralph - collisions wouldnt work properly, and camera wouldnt follow Z coord of character.
I simply want to jump him up (for example 10 units in 0.5 sec) and fall him back in such way with with respect to direction. May be in same situations he can jump higher or faster - i want to control that.
If i press spacebar key until previus jump not finished - how to protect Ralph of jumping twicely?

I try to use intervals and tasks to make him jumping, but i’m absolutly noob - and nothing works properly :frowning:

I am also at the very beginning of learning Panda3D.
First of all, I would create an empty “dummy” node and reparent Ralph to it rather then “render” itself. The reason is he was created in Maya and uses Y as top-down axis, while the engine uses Z. This way you can avoid many potential problems. For example, when you scale a model, it’s own coordinate system is scaled too (another thing, for example, if you scale Ralph at 0.4, then moving him 1 unit away relative to himself is equal to moving him 0.4 units away relative to your world, to the “render”).
If you do so, make your camera track this dummy node, movement buttons should move it instead of Ralph, and collision code should adjust the Z position of this node. Now you can make your Ralph jump :slight_smile:
To prevent him from jumping when jumping, your could do something like this (pseudocode):

time = 1 sec
if jumpKey == 1 and (currentTime-timeWhenJumped) < time:
    makeJump()
    timeWhenJumped = currentTime

Since I am a beginner myself, maybe someone more experienced could suggest another way.
PS: I think this thread should go under “Scripting Issues”, shouldn’t it?

Hi everybody!
Wow! :open_mouth: Ralph can jump now! :smiley: - I did it maybe in some fricky way, but it works. For now - next step - shooting enemies(boxes, for example).Also i want to put compas and HUD on the screen - have anybody some advises for me?

Here is code

from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "show-frame-rate-meter 1") 
from pandac.PandaModules import CollisionTraverser,CollisionNode
from pandac.PandaModules import CollisionHandlerQueue,CollisionRay
from pandac.PandaModules import WindowProperties
from direct.showbase.DirectObject import DirectObject # To listen for Events
from direct.task import Task # To use Tasks 
from direct.actor.Actor import Actor
from pandac.PandaModules import Vec3,Vec4,BitMask32
from direct.gui.OnscreenText import OnscreenText
import direct.directbase.DirectStart
from pandac.PandaModules import ConfigVariableString 
import sys, os, math
from pandac.PandaModules import Filename
from pandac.PandaModules import PandaNode,NodePath,Camera,TextNode
from direct.gui.OnscreenText import OnscreenText
from direct.task.Task import Task

MYDIR=os.path.abspath(sys.path[0])
MYDIR=Filename.fromOsSpecific(MYDIR).getFullpath()

# Function to put instructions on the screen.
def addInstructions(pos, msg):
    return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
			pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)

# Function to put title on the screen.
def addTitle(text):
    return OnscreenText(text=text, style=1, fg=(1,1,1,1),
	                pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)
                        
class World(DirectObject):
  def __init__(self):
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)
	base.setBackgroundColor(0, 0, 0)    
	base.disableMouse()                 
	camera.setPos ( 0, 0, 20 )          
	camera.setHpr ( 0, 0, 0 )
	self.heading = 180
	self.pitch = 0	
        
        self.title = addTitle("Third person shooter template")
        self.inst1 = addInstructions(0.95, "[ESC]: Quit")
        self.inst2 = addInstructions(0.90, "[A]: Strafe Left")
        self.inst3 = addInstructions(0.85, "[D]: Strafe Right")
        self.inst4 = addInstructions(0.80, "[W]: Run Forward")
        self.inst6 = addInstructions(0.75, "[S]: Run backward")
        self.inst7 = addInstructions(0.65, "[Shift]: Acceleration")
        self.inst7 = addInstructions(0.55, "[Mouse]: Camera control")
        self.inst7 = addInstructions(0.70, "[Spacebar]: Jump")        
	self.keys = {"strafeLeft" : 0, "strafeRight": 0,
				 "accel": 0, "back": 0, "jump": 0, "run": 0}

	self.accept("escape", sys.exit)            #Escape quits
	#Other keys events set the appropriate value in our key dictionary
	self.accept("a",     self.setKey, ["strafeLeft", 1])
	self.accept("a-up",  self.setKey, ["strafeLeft", 0])
	self.accept("d",    self.setKey, ["strafeRight", 1])
	self.accept("d-up", self.setKey, ["strafeRight", 0])
	self.accept("w",       self.setKey, ["accel", 1])
	self.accept("w-up",    self.setKey, ["accel", 0])
	self.accept("s",       self.setKey, ["back", 1])
	self.accept("s-up",    self.setKey, ["back", 0])
	self.accept("space",       self.setKey, ["jump", 1])
	self.accept("space-up",    self.setKey, ["jump", 0])
	self.accept("shift",       self.setKey, ["run", 1])
	self.accept("shift-up",    self.setKey, ["run", 0])
	self.accept("shift-a",     self.setKey, ["strafeLeft", 1])
	self.accept("shift-a-up",  self.setKey, ["strafeLeft", 0])
	self.accept("shift-d",    self.setKey, ["strafeRight", 1])
	self.accept("shift-d-up", self.setKey, ["strafeRight", 0])
	self.accept("shift-w",       self.setKey, ["accel", 1])
	self.accept("shift-w-up",    self.setKey, ["accel", 0])
	self.accept("shift-s",       self.setKey, ["back", 1])
	self.accept("shift-s-up",    self.setKey, ["back", 0])
         
        self.isMoving = False
        self.startJump = False
        self.jump = False
        self.t = 0.0                        
        self.environ = loader.loadModel("models/world")      
        self.environ.reparentTo(render)
        self.environ.setPos(0,0,0)
        self.environ.setScale(5,5,5)
        StartPos = self.environ.find("**/start_point").getPos()
	# create dummy cam to which the gun can be attached
	self.c_node = render.attachNewNode("camera_dummy_node") 
        self.ralph = Actor("models/ralph",
                                 {"run":"models/ralph-run",
                                  "walk":"models/ralph-walk"})                                  
        self.ralph.reparentTo(render)
        self.ralph.setScale(1.0)
        self.ralph.setHpr(0,0,0)	
	# Set angles
	self.c_node.setHpr(0, 0, 0)	  
	# Attach the camera to the dummy node. 
	camera.reparentTo(self.c_node)
        self.c_node.setPos(StartPos)
	self.ralph.setPos(StartPos)	
	# Position the camera 
	camera.setPosHpr(Vec3(0,-40,10),Vec3(0,0,0))
	self.prevtime = 0
        
        self.cTrav = CollisionTraverser()
        self.ralphGroundRay = CollisionRay()
        self.ralphGroundRay.setOrigin(0,0,1000)
        self.ralphGroundRay.setDirection(0,0,-1)
        self.ralphGroundCol = CollisionNode('ralphRay')
        self.ralphGroundCol.addSolid(self.ralphGroundRay)
        self.ralphGroundCol.setFromCollideMask(BitMask32.bit(0))
        self.ralphGroundCol.setIntoCollideMask(BitMask32.allOff())
        self.ralphGroundColNp = self.c_node.attachNewNode(self.ralphGroundCol)
        self.ralphGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler)
        
	self.gameTask = taskMgr.add(self.gameLoop, "gameLoop")
	self.gameTask.last = 0
                
        # Uncomment this line to see the collision rays
        #self.ralphGroundColNp.show()
        #Uncomment this line to show a visual representation of the 
        #collisions occuring
        #self.cTrav.showCollisions(render)         
  def setKey(self, key, val):
	  self.keys[key] = val
  def gameLoop(self, task):
	self.elapsed = task.time - self.prevtime
        startpos = self.c_node.getPos()
	if self.keys["strafeLeft"]:
		self.strafe(-1)
	if self.keys["strafeRight"]:
		self.strafe(1)
	if self.keys["accel"]:
		self.walk(1)
	if self.keys["back"]:
		self.walk(-1)
	self.MouseTask()
	if self.keys["accel"] and self.keys["run"]:
		self.walk(2)
	if self.keys["back"] and self.keys["run"]:
		self.walk(-2)
        if self.keys["accel"] or self.keys["strafeLeft"] or self.keys["strafeRight"] or self.keys["back"]:
            if self.isMoving is False:
                self.ralph.loop("run")
                self.isMoving = True
        else:
            if self.isMoving:
                self.ralph.stop()
                self.ralph.pose("walk",5)
                self.isMoving = False
	if self.keys["jump"] and not self.jump:
            self.startJump = True
	if self.startJump:
            self.t = globalClock.getFrameTime()
            self.startJump = False
            self.jump = True
	if self.jump:
            self.Jump (self.t)
                
        self.cTrav.traverse(render)
        # Adjust camera dummy node Z coordinate.  If c_node ray hit terrain,
        # update his Z. If it hit anything else, or didn't hit anything, put
        # it back where he was last frame.
        entries = []
        for i in range(self.ralphGroundHandler.getNumEntries()):
            entry = self.ralphGroundHandler.getEntry(i)
            entries.append(entry)
        entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
                                     x.getSurfacePoint(render).getZ()))
        if (len(entries)>0) and (entries[0].getIntoNode().getName() == "terrain"):
            h = entries[0].getSurfacePoint(render).getZ()
            self.c_node.setZ(h)
            if not self.jump:
                    self.ralph.setZ(h)
        else:
            self.c_node.setPos(startpos)
            if not self.jump:
                    self.ralph.setPos(startpos)             
	self.MouseTask()		
	self.prevtime = task.time
	return Task.cont
  def Jump(self,time):
        elapsed = self.elapsed
        z = self.c_node.getZ()
        zr = self.ralph.getZ()
        i=globalClock.getFrameTime()
        f=i-time
        t = elapsed*40
        if f <= 0.2:   
                self.ralph.setZ(self.ralph.getZ() + t)
                self.ralph.setX(self.c_node.getX())
                self.ralph.setY(self.c_node.getY())
                self.jump = True

        if f > 0.2 :
            d = self.ralph.getDistance( self.c_node)
            if (d > 2):
                self.ralph.setZ(self.ralph.getZ() - t)
                self.ralph.setX(self.c_node.getX())
                self.ralph.setY(self.c_node.getY())
                self.jump = True
                           
            else :
                self.ralph.setPos(self.c_node.getPos())
                self.jump = False

  def strafe(self,dir):
	  elapsed = self.elapsed
	  strafe = self.c_node.getNetTransform().getMat().getRow3(0)
          strafe.setZ(0)
	  strafe.normalize()
          i = strafe*(elapsed*45*dir)
	  self.c_node.setPos(self.c_node.getPos() + i)
	  self.ralph.setPos(self.ralph.getPos() + i)
  def walk(self,speed):
	  elapsed = self.elapsed
	  forward = self.c_node.getNetTransform().getMat().getRow3(1)
	  forward.setZ(0)
	  forward.normalize()
          i = forward*(elapsed*45*speed)
	  self.c_node.setPos(self.c_node.getPos() + i)
	  self.ralph.setPos(self.ralph.getPos() + i)
                
  def MouseTask(self):
	  try:
		x = base.win.getPointer(0).getX()
		y = base.win.getPointer(0).getY()

		if base.win.movePointer(0, 100, 100):
				self.heading = self.heading - (x - 100)*0.2
				self.pitch = self.pitch - (y - 100)*0.2
		if (self.pitch < -45): self.pitch = -45
		if (self.pitch >  -3): self.pitch =  -3
		self.c_node.setHpr(self.heading,self.pitch,0)
                self.ralph.setH(self.heading +180)
	  except: pass


w = World()
run()

and file
http://www.sharemania.ru/0252389

I made a HUD and a radar for some of my programs. You’re welcome to copy them.

They can be found at my P3DP.com page- You can find the link in my signature.

Thank a lot! It’s pretty cool and very-very useful. Very soon i make my version of radar.
One more question - i try to make weapon toggle using mouse wheel:

	
self.cur_weap = 1 #This string in _init_
...
        self.accept("wheel_up",       self.setKey, ["weapon_up", 1])
        self.accept("wheel_down",    self.setKey, ["weapon_down", 1])

...
#This strings in gameLoop
if self.keys["weapon_up"] :
            self.weapon_up()  
       
if self.keys["weapon_down"] :
            self.weapon_down()
 
  def weapon_up(self):
        self.cur_weap = self.cur_weap + 1
        if self.cur_weap > 3:
            self.cur_weap = 3
            self.weapon_redraw()
            
                                                             
  def weapon_down(self):
        self.cur_weap = self.cur_weap - 1
        if self.cur_weap < 1:
            self.cur_weap = 1
            self.weapon_redraw()
  def weapon_redraw(self):
      
            if self.cur_weap == 1:
                    self.weap1.setImage("weap_1.png")
                    self.weap2.setImage("weap_0.png")
                    self.weap3.setImage("weap_0.png")
                          
            if self.cur_weap == 2:
                    self.weap1.setImage("weap_0.png")
                    self.weap2.setImage("weap_1.png")
                    self.weap3.setImage("weap_0.png")

            if self.cur_weap == 3:
                    self.weap1.setImage("weap_0.png")
                    self.weap2.setImage("weap_0.png")
                    self.weap3.setImage("weap_1.png")
        

 

… but it work in wrong way (i can’t change weapon down) :frowning:

My suggestion :
don’t use someone else’s code without knowing what exactly it does. It’s dangerous !

You’re using a mapping to set a button’s down state. But mouse wheel doesn’t have “-up” events. So if you insist to use a mapping, you should restore its value back to 0 in both weapon_up and weapon_down.

  def weapon_up(self):
        self.keys["weapon_up"]=0
        self.cur_weap = self.cur_weap + 1
        if self.cur_weap > 3:
            self.cur_weap = 3
            self.weapon_redraw()

  def weapon_down(self):
        self.keys["weapon_down"]=0
        self.cur_weap = self.cur_weap - 1
        if self.cur_weap < 1:
            self.cur_weap = 1
            self.weapon_redraw()

Or, don’t use mapping at all for mouse wheel :

        self.accept("wheel_up",   self.weapon_up)
        self.accept("wheel_down", self.weapon_down)

:smiley: Thanks, now Ralph can change his weapon(only images for now). Also he has very simple radar with map, TPS/FPS camera toggle and a BigRalf as an enemy . And again - can anyone help - how to show BigRalph position on radar map?( just how place on map texture another texture(simple dot for example) with respect to BigRalph position)

screenshot:
http://www.sharemania.ru/0167566
file(without ralph tut models):
http://www.sharemania.ru/0137545
Extract to C:\Panda3D-1.4.2\samples\Sample-Programs–Roaming-Ralph

From looking over your code, it looks like you have some bad habits when it comes to spacing. What editor/IDE are you using, if any? If you aren’t using one, then I suggest you get one. I’m using Komodo Edit, it’s pretty customizable. If you are using one, maybe you should set it to keep an eye out for mistakes in whitespace or mixing spaces and indents.

Remember to always be consistent when it comes to either indenting or using the spacebar. If you don’t watch out about whitespace, it may come back to haunt you. Your code also looks nicer and is easier to read if you are consistent.

Just a suggestion, but of course you don’t have to follow my advice. I’m still a beginner with Panda myself, after all.

Sorry i am entirely New to python and i was wondering if it is possible to modify this code so that the mousetrack is only active when the right mouse button is pressed and de-activates when you release it?

i’ll have a mess around see if i manage anything but i doubt i will get anywhere.

any ideas? :wink:

Hehe, I tried to do the same thing myself. The real issue for me wasn’t getting it to run on only right click (this is simple, just call the function on right click instead of the loop, or on right click set a variable that is checked inside the function itself), but stopping the strange little glitches that happen when you move the mouse away from that point the mouse gets moved to and then click the right mouse button. My solution was basically moving the mouse to that spot on right click and setting rightClick to 1, then 0 when it’s released (or something along those lines, I can’t remember since I basically used it to learn from and then rewrote the code in a different way). In the function that controls the mouse (can’t remember what it’s called) I check if rightClick is True, then run the function.

Pretty simple workaround if you really want that. If you have no idea what I’m talking about you should first learn python (panda3d.org/manual/index.php/Main_Page). If you don’t understand just because I write in a confusing way, just ask me and I’ll give more detail.

Eventually, you should be able to come back to this code and know exactly what it’s talking about and then be able to change it. Remember, you can’t edit it properly until you understand it properly.

I Understand, ive worked with ther coding languages before and
they are all reletively similar.

You mean that when i hold the right mouse button it will switch a variable
so something like

#--- Switches the Free Roam Cam On
self.accept("mouse3", self.setKey, ["free-roam-cam", 1])
#--- Releasing the button will Switch it off
self.accept("mouse3-up", self.setKey, ["free-roam-cam", 0])

then something along the lines of.

  def MouseTask(self):
#---If Free Roam Cam Is Switched On
 if (self.keyMap["free-roam-cam"]!=1):
#--then perform the mouse task.
	  try:
              if not self.m_c:
		 x = base.win.getPointer(0).getX()
		 y = base.win.getPointer(0).getY()

		 if base.win.movePointer(0, 100, 100):
				self.heading = self.heading - (x - 100)*0.2
				self.pitch = self.pitch - (y - 100)*0.2
		 if (self.pitch < -45): self.pitch = -45
		 if (self.pitch >  20): self.pitch =  20
		 self.c_node.setHpr(self.heading,self.pitch,0)
                 
                 self.ralph.setH(self.heading +180) 
                          
	  except: pass

now don’t get me wrong, that was 5 minutes of pure guessing there.
so it most likely wont work, but thats the idea right? :wink:

newfych:

Thanks for your post. I tried to download the files from the link you gave at the end of your post. Unfortunately I do not read Russian. I surmised that you just type in the numbers into the input box on that page to verifiy that its and actual human trying to download the file. BUT when I did that I got Internet Explorers warning bar that cautions against downloading files. Thats normal it happens all over the web when you try to download something. So I right-clicked on it and chose to download the file. Well all that happened was that I got back to the original page where you are suppose to input the verification numbers. There was no dialog box to save the file to a directory, as normally happens.

All this make me VERY SUSPECT of that site and the files. You might want to find another file hosting service.

Shaba1: That sight seems to work fine, at least for me. The thing with that site is that after you type in the code, hit enter. Then when that new page opens up, you have to wait for the download box to pop up from that page. If the pop up doesn’t come up, you can simply press the first link in the first little paragraph that has the header that reads, "Загрузка файла начнетÑ

Hi! Still need advise, how to paint something on map (dinamically)?
Now ralph can shoot something :smiley: with bullets (seems like drawing) for now and with missles. code very dirty, i know.
link on rapidshare:
http://rapidshare.com/files/107157490/TPS.zip.html
800 kb
thks for ansewrs. Now i modelling my own level and hero - it must be much easyer to work with own models.

Please see this for painting on textures:
discourse.panda3d.org/viewtopic.php?t=2325

newfych:
I download this file. Two problems

#1 the models are not in a folder of their own called “models” within the zip.
After I corrected that (moved all the *.egg files to a sub directory called “models”) I ran tps3.py and got this error

 C:\Documents and Settings\Owner\Desktop\MyProjects\Panda3d\Roamers2>python tps3.
py
DirectStart: Starting the game.
Warning: DirectNotify: category 'Interval' already exists
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
:util(warning): Adjusting global clock's real time by 8.10622e-006 seconds.
:loader(error): Couldn't load file map.egg: not found on model path (currently:
"/c/Documents and Settings/Owner/Desktop/MyProjects/Panda3d/Roamers2;/c/Panda3D-
1.5.0/etc/..;/c/Panda3D-1.5.0/etc/../models")
Assertion failed: !is_empty() at line 874 of panda/src/pgraph/nodePath.cxx
Traceback (most recent call last):
  File "tps3.py", line 499, in <module>
    w = World()
  File "tps3.py", line 51, in __init__
    self.GUIsetup()
  File "tps3.py", line 144, in GUIsetup
    self.map = OnscreenGeom( geom = self.MAP,parent = as,scale = sc,pos = (-1.1,
 0, -0.8),hpr = (0,90,0))
  File "c:\Panda3D-1.5.0\direct\src\gui\OnscreenGeom.py", line 55, in __init__
    apply(self.setPos, pos)
AssertionError: !is_empty() at line 874 of panda/src/pgraph/nodePath.cxx

I have no idea what this means. i looked into OnscreenGeom.py and all looks good there. But not nodePath.cxx,since I am not good with C/C++ code.

Hi, Shaba1!
All files of TPS.zip must be extracted to C:\Panda3D-1.5.0\samples\Roaming-Ralph, and models of TPS.zip (bullet.egg, map.egg etc…) must be in the same folder with tps3.py. I do that, because it’s easy to separate my files from Ralph’s tutorial.

:frowning: is that what is causing that error. If so I have a problem. I would rather not overwrite the original Roaming Ralph tutorial