Change the radius of a circle collider through script

Change the radius of a circle collider through script
0.0 0


I need to make a dynamic circle collider component for a node.

the prefab i am adding the collider to does not have one already set in cocos creator.

i have tried this…

var Collider = new(cc.Collider.Circle);
Collider.Radius = bombRadius;

I get this error;
Error 3809, please go to to see details.

error 3809
addComponent: The component to add must be a constructor

I thought the better way would be to set a circle collider for the prefab in the cocos creator UI and then just update it through the script on initialization of the prefab however i can’t find the setCircleColliderRadius() function.

Does any one know how i can achieve either of these methods? hopefully both :wink:


You do it in reverse order. addComponent takes a type and ultimately constructs your object for you. Try this instead

cc.director.getCollisionManager().enabledDebugDraw = true;
cc.director.getCollisionManager().enabled = true;
this.node.getComponent(cc.CircleCollider).radius = this.node.width/2;
this.node.getComponent(cc.CircleCollider).enabled = true;


Thank you very much kind sir :slight_smile:


Good Help.