[Resolved] Physics?: How to access and change a physical body radius?

Hi guys,

I maybe blind but I cannot for the life of me found how to change the radius of one of my physics body?

physics.addBody( gunCross,“static”,{radius= 10,isSensor = true})

I tried the obvious “gunCross.radius” but of course that won’t work.

Any pointers will be appreciated.

Thanks.

Mo.

ps: I am not even sure physical bodies parameters can be change on the fly… [import]uid: 49236 topic_id: 23834 reply_id: 323834[/import]

Ok, It sounds that the only way to do this is to remove the physics body first and then re-create one on the fly. I am wondering how on this will affect my fast pace type game.

Basically here what I am trying to do in case someone has some suggestions.

I have a weapon button that i can toggle between two gun types. Gun1 has a destruction radius of 10 and i want gun2 to have a destruction radius of 30. Right now i have a physics body (called gunCross) with a radius of 10.

I may have to setup 2 physics bodies (gunCross1/2) and then check for collision with both them.

Any comments are welcomed. I just do not feel comfortable adding/removing physics bodies on the fly for a fast pace game like mine.

Thanks,

Mo [import]uid: 49236 topic_id: 23834 reply_id: 95979[/import]

How about this.

Create two guns, with the two bodies you need.

When you switch you set the other inactive like so :

mybody.isBodyActive = false  

You may have to wrap that in a timer.performWithDelay [import]uid: 84637 topic_id: 23834 reply_id: 95983[/import]

Thanks Danny! That’s an excellent suggestion. I was going to setup two guns but I forgot about “.isBodyActive” That’s perfect.

Thanks again.

Mo [import]uid: 49236 topic_id: 23834 reply_id: 95985[/import]

Always welcome :slight_smile: [import]uid: 84637 topic_id: 23834 reply_id: 95988[/import]

Very helpful blog post! Thanks so much for all the suggestions, I had a problem changing radius of objects as well and now it’s gone:) I’ll keep doing this way in future to avoid the feeling of confusion.
PDF Viewer [import]uid: 141120 topic_id: 23834 reply_id: 99788[/import]