Misplaced CollisionPolygon??

Hi, and thanks for your attention.

I really can’t figure out why my collision triangle is misplaced.

I am trying to place it with one vertex at the same coordinates as the model (a building) - but it appears outside the building; at a distance that I think is proportional to the buildings distance to (0,0,0).

I am even assigning a variable (named position) to the position to be sure to keep track of it.

The funny thing is that if I # the loadModel then the Triangle is placed where I want it to.

Here is the code:

base.disableMouse()
base.camera.setPos(20,-10,60)
base.camera.setHpr(20,-45,0)
self.building = loader.loadModelCopy(“models/BuildingCluster3/BuildingCluster3”)
self.building.reparentTo(render)
self.building.setScale(.5,.5,.05)
position=Point3(0,40,0)
self.building.setPos(position)
southernTriangle=CollisionPolygon(position , position+Vec3(0,0,10) , position+Vec3(10,0,0))

southCollNode=CollisionNode(“southColl”)
southCollNode.addSolid(southernTriangle)
southColl=self.building.attachNewNode(southCollNode)
southColl.show() #TBD when done

The model is from alice.org/pandagallery/City/BuildingCluster3.zip

I note that you are attaching the polygon to the node self.building. But you have already done self.building.setPos(position)! Remember that a node always inherits its transform from the parent, so that means your collision polygon is inheriting a transform that adds position to its x, y, z–which is also set to position. So the resulting net position of the first vertex of your polygon will be 2 * position.

If you want to put the polygon at the building’s origin, just define it like this:


southernTriangle=CollisionPolygon(Point3(0, 0, 0), Point3(0,0,10) , Point3(10,0,0))

David

Ahh now I get it! Thanks a million drwr.
I wasn’t aware (ermm, forgot to think :blush:) of the inheritance of the transformation.

Now, in my game I want more than just one building at (0,0,0).
In fact I want 16 buildings, spread out in a well-defined pattern.
But I am pretty sure I can make the transformation of the coordinates myself, now that you have helped me.