Choosing coordinatesystem

I’m using a collisionray to detect line of sight between two objects in my game, but I have problems with what coordinate system Panda is using to control the ray. When I call my function LOS the ray should be calculated anew, but this doesn’t seem to work. Has anyone got an idea?

def init(self, obj):

	self.rayNode = CollisionNode('LOS Ray')
	self.rayNodePath = self.object.model.attachNewNode(self.rayNode)
	#self.rayNodePath = render.attachNewNode(self.rayNode)
	self.ray = CollisionRay(0,0,0,0,0,1)

def LOS(self, target):

	dirx = target.model.getX() - self.object.model.getX()
	diry = target.model.getY() - self.object.model.getY()
	dirz = target.model.getZ() - self.object.model.getZ()
	bounds = self.object.model.getChild(0).getBounds()
	center = bounds.getCenter()


The collision node is attached to self.object.model:

self.rayNodePath = self.object.model.attachNewNode(self.rayNode)

That means that the ray is in the coordinate system of the model. If the ray starts at (0,0,0), then it starts in the center of the model. If the model rotates, the ray rotates too.

The code looks like it was written as if the ray were not attached to the model.

Yes, as it is now it uses the coordinate system of its parent node. But if I reparent it to the render it still does not behave as intented.
The initialization

self.ray = CollisionRay(0,0,0,0,0,1)

continues to affect the ray even after it is changed by


Is there some way to force it to use to global coordinate system (that of the render) even when it is attached to another node?

You can still parent the ray to your model, and then switch the coordinate system of the target to the model’s coord system. Basically, it works like this :
sourceObjNodepath.getRelativePoint(targetObjNodepath,[point on targetObj’s coord system])
so, for your problem :

dirx = self.object.model.getRelativePoint(target.model,target.model.getX()) - self.object.model.getX()