CollisionSphere Problem

I’ve tweaking all my old panda1.1 code to work with the current panda3d version. All the packages i’ve imported seem to have changed. I have to search for an object and find that I now have to use pandac or some other package that contains the object.

My Current problem is with CollisionSphere. When I try to use it, it says ‘not defined.’

Where is this located?

Here’s the code if it helps…

from direct.showbase.ShowBaseGlobal import *
from direct.interval.IntervalGlobal import *
from direct.showbase.DirectObject import DirectObject

from direct.gui.OnscreenText import OnscreenText
from direct.gui.OnscreenImage import OnscreenImage
from direct.actor import Actor
from direct.task import Task
from direct.gui.DirectLabel import DirectLabel
from pandac.PandaModules import NodePath

import time
import ClassGlobals
import Player
import Level2
import BackgroundCall
import LoadMusic


class NPC(DirectObject):
	def __init__(self,type):
		
		self.npcType = type
		self.dummyNode = render.attachNewNode('dummyNode')
		self.talkNode = (self.dummyNode.attachNewNode('talkNode'))
		
		#self.npc = loader.loadModelCopy("models/npc%d" % (type, ) )
		self.npc = Actor.Actor("models/npc%d" % (type, ) )
		self.npc.setScale(.3,.3,.3)
		self.npc.reparentTo(self.dummyNode)
		
		self.npcForward=NodePath("forward")
		self.npcForward.setPos(1,0,0)
		self.npcForward.reparentTo(self.npc)

		#Initialize the talk button
		self.talk = loader.loadModel("models/talkbutton")
		self.talk.setPos(0,0,10)
		self.talk.setScale(2,2,2)
		self.talk.reparentTo(self.talkNode)
		self.talk.hide()

		self.Font = loader.loadFont('models/JOINTBYPIZZADUDE.ttf')

		if (type == 1):
			self.dummyNode.setPos(12,-85,0)
		if (type == 2):
			self.dummyNode.setPos(12,85,0)
		if (type == 3):
			self.dummyNode.setPos(-90,25,0)


		#define talk radius
		self.radiusSphere = CollisionSphere(-1,0,5,70)
		self.collNPCRadius = CollisionNode("npcRadius%d" % (type, ))
		radius = self.collNPCRadius.addSolid(self.radiusSphere)
		self.collNPCRadius.getSolid(radius).setTangible(False)
		self.NPCRadius = self.npc.attachNewNode(self.collNPCRadius)
		#self.NPCRadius.show()
		
		#define collision sphere
		self.NPCSphere = CollisionSphere(0,0,5,10)
		self.collNPC = CollisionNode("collNPC")
		self.collNPC.addSolid(self.NPCSphere)
		self.NPCcollision = self.npc.attachNewNode(self.collNPC)
		#self.NPCcollision.show()
		
		#Initialize Text
		self.text1 = ["Hi Puckman!","Welcome to the wonderful world of Troy!","You're a legend, the mascot of the famous RPI!",
						"Defender of the weak, you protect the citizens of Troy who can't protect themselves.","However, beware the enemy Clarkson.",
						"They've been the rivals of RPI for as long as I can remember.","Clarkson used to be a wonderful and pretty place of candy canes and fun was to be had by all!",
						"Until the Golden Knight came.","Potsdam became a dark and sad place where people didn't care about one another:(.",
						"So now, its up to you Puckman!","Defeat the Golden Knight and his minions and bring peace and prosperity to Potsdam once again!"]
		self.text2 = ["Hey there Puckman, and welcome.","I'm going to help you learn how to navigate and defeat enemies should you encounter them in your travels.",
						"For movement, use the 'w' key to move forward and the 's' key to move backwards.",
						"The 'a' key will rotate you left, the 'd' key to rotate you right, and the 'j' key for jumping.",
						"To defend yourself against enemies, use your hockey stick by hitting the 'k' key to swing it.",
						"To interact with friendly people and to read signs, use the 't' key.","Come talk to me again if you ever forget!"]
		self.text3 = ["Beware the end is at hand!","Behold the Omega Gate!","One of the greatest unknowns in the universe.",
						"Many speculate as to where it came from but it remains a mystery.","Careful!",
						"Step through the gate and you will be transported to the realm of Potsdam, land of Clarkson!",
						"Do you wish to enter? (Y/N)"]
		self.count = 0
		
		self.textBox = OnscreenImage(image = 'models/textBox.png', pos = (0,0,-.8),
								scale = (1,1,.18))
		self.textObject = OnscreenText(text = '', pos = (0,-0.72), scale = .08,
								fg = (1,0,0,1), font = self.Font,wordwrap = 24,mayChange=True)
		self.textContinue = OnscreenText(text = 'T to continue ->', pos=(.7,-0.95),
								scale = .05, fg = (1,0,0,1), font = self.Font)
		
		self.textObject.hide()
		self.textContinue.hide()
		self.textBox.hide()
	
	
	#task to ignore the keys
	def ignoreAnim(self,task):
		ClassGlobals.p1.puckWalk.stop("walk")
		return Task.cont
	#define the start function to start the talking
	def startTalk(self):
		
		#need a task to continual ignore animations until done talking
		taskMgr.add(self.ignoreAnim,"ignoreAnim")	
		taskMgr.remove("movepuck")	
		taskMgr.remove("turnpuck")	
		taskMgr.remove("jumppuck")
		taskMgr.remove("fightpuck")
	
		ClassGlobals.p1.puckWalk.lookAt(self.npc)
		ClassGlobals.p1.puckWalk.setH(ClassGlobals.p1.puckWalk.getH()+90)
		###Doesnt work for some reason###
		#camera.setPos(-25,20,10)
		#camera.lookAt(self.npc)
		
		
		if(self.npcType==1):
			if(self.count == len(self.text1)):
				self.count = 0
				self.textBox.hide()
				self.textObject.hide()
				self.textContinue.hide()
				camera.setPos(-150,0,90)
				camera.lookAt(ClassGlobals.p1.puckWalk,0,0,15)
				
				#add moving task back in
				taskMgr.remove("ignoreAnim")
				taskMgr.add(ClassGlobals.p1.movepuckTask,"movepuck")	
				taskMgr.add(ClassGlobals.p1.turnpuckTask,"turnpuck")	
				taskMgr.add(ClassGlobals.p1.jumppuckTask,"jumppuck")
				taskMgr.add(ClassGlobals.p1.fightpuckTask,"fightpuck")
			else:
				self.textBox.show()
				self.textObject.setText(self.text1[self.count])
				self.textObject.show()
				self.textContinue.show()
				self.count += 1
		if(self.npcType==2):
			if(self.count == len(self.text2)):
				self.count = 0
				self.textBox.hide()
				self.textObject.hide()
				self.textContinue.hide()
				camera.setPos(-150,0,90)
				camera.lookAt(ClassGlobals.p1.puckWalk,0,0,15)
				
				#add moving task back in
				taskMgr.remove("ignoreAnim")
				taskMgr.add(ClassGlobals.p1.movepuckTask,"movepuck")	
				taskMgr.add(ClassGlobals.p1.turnpuckTask,"turnpuck")	
				taskMgr.add(ClassGlobals.p1.jumppuckTask,"jumppuck")
				taskMgr.add(ClassGlobals.p1.fightpuckTask,"fightpuck")
				
			else:
				self.textBox.show()
				self.textObject.setText(self.text2[self.count])
				self.textObject.show()
				self.textContinue.show()
				self.count += 1
		if(self.npcType==3):
			if(self.count == len(self.text3)):
				self.count = 0
				self.textBox.hide()
				self.textObject.hide()
				self.textContinue.hide()
				camera.setPos(-150,0,90)
				camera.lookAt(ClassGlobals.p1.puckWalk,0,0,15)
				
				#add moving task back in
				taskMgr.remove("ignoreAnim")
				taskMgr.add(ClassGlobals.p1.movepuckTask,"movepuck")	
				taskMgr.add(ClassGlobals.p1.turnpuckTask,"turnpuck")	
				taskMgr.add(ClassGlobals.p1.jumppuckTask,"jumppuck")
				taskMgr.add(ClassGlobals.p1.fightpuckTask,"fightpuck")
				
				self.ignore("y")
				self.ignore("n")
			else:
				self.textBox.show()
				self.textObject.setText(self.text3[self.count])
				self.textObject.show()
				self.textContinue.show()
				self.count += 1
				if(self.count == len(self.text3)):
					self.acceptOnce("y",self.nextLevel)
					self.acceptOnce("n",self.startTalk)
		self.acceptOnce("t",self.startTalk)
	
	#used to define action once inside a NPC's radius
	#display the talk icon and accept T	
	def npcRadiusHandler(self,colEntry):
		#print "Inside the Radius"
		self.talk.show()
		#self.textBox.show()
		#self.textObject.show()
		self.acceptOnce("t",self.startTalk)
		
	def npcRadiusExit(self,colEntry):
		self.talk.hide()
		self.textObject.hide()
		self.textBox.hide()
		self.textContinue.hide()
		self.ignore("t")
		self.ignore("y")
		self.ignore("n")
	def load(self):
		ClassGlobals.level.__del__()
		ClassGlobals.level = Level2.Level2()
		ClassGlobals.e1.load()
	def nextLevel(self):
		###Loading the cut scene###
		self.cutModel = DirectLabel(image="models/portalLoad.jpg", scale = (1.35,1,1))
		self.cutModel.setPos(0,0,0)
		self.cutModel.show()
		
		self.cutInterval = ShowInterval(self.cutModel)
		self.hideInterval = HideInterval(self.cutModel)

		self.cutSequence = Sequence(self.cutInterval,Wait(15.0),self.hideInterval)
		self.cutSequence.start()

		print "NEXT LEVEL"
		taskMgr.remove("ignoreAnim")
		taskMgr.add(ClassGlobals.p1.movepuckTask,"movepuck")	
		taskMgr.add(ClassGlobals.p1.turnpuckTask,"turnpuck")	
		taskMgr.add(ClassGlobals.p1.jumppuckTask,"jumppuck")
		taskMgr.add(ClassGlobals.p1.fightpuckTask,"fightpuck")
		LoadMusic.RPIMusicInt.finish()
		LoadMusic.PotsdamInt.loop()
		bkcall = BackgroundCall.BackgroundCall(self.load)
		

[/code]

Nevermind… found it and figured out how to get the code to run. Game barely works and I’m done with panda3D. Camera goes outside of level and shakes constantly. Player randomly slides around level depnding on camera movement. No point in using anything when the code doesn’t work at all 2 years later.

Doesn’t sound like the engine, but the programmer, eh?

Problem is, you haven’t even imported CollisionSphere. Like this:
from pandac.PandaModules import CollisionSphere
If you’re lazy and want to import the whole thing, do:
from pandac.PandaModules import *