Change collision sphere size

Hey, is there a simple way to change a collision sphere size after you made it? I have a object can can/will change size, so I need to change the collision size each time.

The API reference, as ugly as it is, is also your friend. :slight_smile:

http://www.panda3d.org/apiref.php?page=CollisionSphere#setRadius

David

I know ^^ I use it all the time.

Werid tho… I tried .setRadius, but what ever reason it’s saying it doesn’t have that attribute…

So I’m totally missing something here o.o; lol.

Heres my collision code… for my camera/soon to be player.

      #Add a collision sphere around our camera.
      self.cnodePath = base.camera.attachNewNode(CollisionNode('camera'))
      self.cnodePath.node().addSolid(CollisionSphere(0, 0, 0, 1.4))
      self.cnodePath.node().setIntoCollideMask(BitMask32.allOff())
      self.cnodePath.node().setFromCollideMask(BitMask32.bit(1)) 
      base.pusher.addCollider(self.cnodePath,base.camera,base.drive.node())
      base.cTrav.addCollider(self.cnodePath,base.pusher)

So from that I did this:
self.cnodePath.node().setRadius(.7)

Guessing I did something wrong here:)

Right, you’re trying to call it on the CollisionNode, not the CollisionSphere, which you added to the node.

David

Sorry, I guess I’m a little lost on how to go about fixing by what you said… Don’t mind showing the code would you? I tried a few different ways and I end up causing more harm than good lol.

It’s a confusion between the CollisionNode, which you create on the first line and add as the node within cnodePath, and the CollisionSphere, which you create on the second line and add as the solid within your CollisionNode.

So, self.cnodePath is a NodePath. It contains a node, which is your CollisionNode. The CollisionNode contains a solid, which is your CollisionSphere.

One easy way to get to your sphere is with self.cnodePath.node().getSolid(0).

Or, you could just save a pointer to the sphere in the first place:

self.csphere = CollisionSphere(0, 0, 0, 1.4)
self.cnodePath.node().addSolid(self.csphere)

And then self.csphere would be a handle to your CollisionSphere.

David

Thanks drwr. Yea, I guess I was just getting confusied with how I had things setup. Thank you for making it clear for me.