shimrod
December 6, 2011, 2:05pm
#1
Hello,
I am using bullet, and I am testing collision, and I wish to know the pos of one of the object collided:
result = world.contactTest(self.bodyNP.node())
for node in result.getContacts():
myFirstObject=node.getNode1()
print myFirstObject.getPos()
AttributeError: 'libpandabullet.BulletGhostNode' object has no attribute 'getPos'
or
AttributeError: 'libpandabullet.BulletRigidBodyNode' object has no attribute 'getPos'
I am colliding one bulletGhostNode with a bulletRigidBodyNode.
How can I retrieve position from this bulletNode?
Thanks
[/code]
peaches
December 6, 2011, 2:46pm
#2
I’m not exactly sure what your code does, but this is what I use for ‘bullet’ collision.
self.pickerTraverser.traverse(render)
entries = []
for i in range(self.pickerCollisionHandler.getNumEntries()):
entry = self.pickerCollisionHandler.getEntry(i)
entries.append(entry)
if(len(entries) > 0):
entries.sort(lambda x,y: cmp(self.DistanceFromCam(x.getSurfacePoint(render)),
self.DistanceFromCam(y.getSurfacePoint(render))))
point = entries[0].getSurfacePoint(render)
The important part is entry.getSurfacePoint(render). The Collision Entry objects are what contain all of the useful information about a collision.
shimrod
December 6, 2011, 4:27pm
#3
In fact, I use bullet (the physic engine) to create node, and manage collision.
My program runs as a server, and it is about AI, and not for the player himself.
So I don’t think your solution can be applyable.
I think it must be an easier way to grab position from collision test
But thank you for your time
enn0x
December 6, 2011, 4:36pm
#4
BulletRigidBodyNode is derived from PandaNode. You can get the position the same way as you would get it from any other node in the scene graph (e. g. a GeomNode):
node.getTransform().getPos()
Or you create a NodePath for this node:
np = NodePath(node)
np.getPos()