-
I need to spawn monsters at random points a model (uneven), right now what I am doing is to use a collision ray and place the monster at a very, very high place. Is there a better way to do that?
-
Can I tell panda to calculate collision of a given model? For example I have 10 collision solids added in the traverse, can I tell him do calculate the collision to a given one and not for the others?
Thanks in advance.
EDIT:
I changed the topic subject so people can find it easier with the search engine.
Solved, here is the code in case anyone got the same problem:
class player:
def __init__(self, posX, posY):
# Place it in an invalid x, y and a very high z
self.posX = -1000
self.posY = -1000
self.posZ = 1000
self.angle = angle
self.model = Actor("models/panda-model", {"walk": "models/panda-walk4"})
self.model.reparentTo(render)
#Please notice that the ray is affected by the scale (if any)
self.groundRay = self.model.attachNewNode(CollisionNode('colNode'))
self.groundRay.node().addSolid(CollisionRay(0, 0, 1, 0, 0, -1))
# Remove the comment to see the ray
#self.groundRay.show()
self.collisionQueue = CollisionHandlerQueue()
# temporary traverser
specialTrav = CollisionTraverser()
specialTrav.addCollider(self.groundRay, self.collisionQueue)
# now we move the object, if the position is valid it will detect the ground
self.posX = posX
self.posY = posY
specialTrav.traverse(render)
entriesNum = self.collisionQueue.getNumEntries()
if (entriesNum > 0):
self.posZ = self.getCollisionQueue().getEntry(entriesNum-1).getSurfacePoint(render).getZ()
self.collisionQueue.clearEntries()
else:
print("Error: No collision detected.\nThe point you tried to place the model may be out of bounds or you forgot to load the other models")
# clearing the special traverser
specialTrav.clearColliders()
specialTrav = None