I am attempting to apply simple collisions to three panda models, but I keep getting this error:
:collide(error): Invalid attempt to detect collision from CollisionRay into CollisionRay!
This means that a CollisionRay object attempted to test for an
intersection into a CollisionRay object. This intersection
test has not yet been defined; it is possible the CollisionRay
object is not intended to be collidable. Consider calling
set_into_collide_mask(0) on the CollisionRay object, or
set_from_collide_mask(0) on the CollisionRay object.
I’ve been looking around and havent found/understood what the error is nyahah, can anyone help me?
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject # Used for events I belive [CHECK]
from direct.task import Task # Uses for tasks
import sys # used for events and all them nekos ^-^
from pandac.PandaModules import *
# - Create a more effective way to load many NPCs
# - Apply Collisions to them individualy
class collisionClass():
def __init__(self, classNode, num=None):
self.node = classNode
self.collTrav = CollisionTraverser() #the collision traverser. we need this to perform collide in the end
self.collTrav.showCollisions(render) #just to visualize the collisions
#setting up a collision handler queue which will collect the collisions in a list
queue = CollisionHandlerQueue()
print "Len of NPC: ", len(num)
# this is an array, that was created, then added to each time a NPC node was added to the scene
for child in num:
#our "from" node which is able to bump into "into" objects gets attached to the player
fromObject = child.attachNewNode(CollisionNode('colNode'))
#the actual solid which will be used as "from" object. in this case a ray pointing downwards from the players center
fromObject.node().addSolid(CollisionRay(0, 0, 0, 0, 0, -1))
#and now we turn turn of the collision for the playermodel so it wont collide with the ray or anything.
child.node().setIntoCollideMask(BitMask32.allOff())
#now set the bitmask of the "from" object to match the bitmask of the "into" object
fromObject.node().setFromCollideMask(BitMask32.bit(1))
#add the from object to the queue so its collisions will get listed in it.
self.collTrav.addCollider(fromObject, queue)
#this just visualizes the collision ray so we can see it.
fromObject.show()
#print child.ls()
self.collTrav.traverse(render)
for i in range(queue.getNumEntries()):
entry = queue.getEntry(i)
print entry
class world(DirectObject):
def __init__(self):
self.accept("escape", sys.exit)
# Create flat floor
cm=CardMaker('')
cm.setFrame(-2,2,-2,2)
floor = render.attachNewNode(PandaNode("Floor"))
floor.setCollideMask(BitMask32.bit(1))
for y in range(12):
for x in range(12):
nn = floor.attachNewNode(cm.generate())
nn.setP(-90)
nn.setPos((x-6)*4, (y-6)*4, 0)
floor.flattenStrong()
self.npcRoot = render.attachNewNode("npcRoot") # Root of all Evil erm NPC
self.npc = []
for i in range (3):
self.miyu = self.npcRoot.attachNewNode(PandaNode('npc_miyu')) # Attach an NPC to the root
self.miyu = loader.loadModel("panda")
self.miyu.setPos(0,10*i,20)
self.miyu.reparentTo(self.npcRoot)
self.npc.append(self.miyu)
collisionClass(self.npcRoot, self.npc)
world()
run()