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:


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 ='camera'))
      self.cnodePath.node().addSolid(CollisionSphere(0, 0, 0, 1.4))

So from that I did this:

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.


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)

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


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