[Solved]Two quick questions - Finding Z pos on load

  1. 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?

  2. 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.


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"})

		#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.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
		entriesNum = self.collisionQueue.getNumEntries()
		if (entriesNum > 0):
			self.posZ = self.getCollisionQueue().getEntry(entriesNum-1).getSurfacePoint(render).getZ()
			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 = None

(1) There are other approaches, but there’s nothing wrong with that one.

(2) You can create a separate CollisionTraverser for your model, add only that one model to it, and call traverse.traverse(render) explicitly.

The only potential problem with #1 is that if you are implementing fall damage :slight_smile: Can’t have those spawning monsters dying from hitting the ground :wink:

Really nice idea, should have though about that… I fell stupid now =(


Yeah, that is the main problem I am facing, I can manage to work it with a boolean variable that says if it is in process of creation… but that is an unnecessary check that will be run a load of times…

Anyways, I know how to do that now… thanks a lot.