Gyutang Posted December 6, 2015 Share Posted December 6, 2015 I was trying to change the mass of a Box2d body in a PostsolveCollisionCallback, but it was not working as I intended.I checked the behavior in a debugger, and I found out that any of properties of Box2d body (e.g. mass, velocity) could not be changed inside a callback function. I guess this is because those parameters are necessary for some physical calculation, but I would like to know if the is any workaround for this. For now I just created a time event to modify the parameters. I went through the documentation but nothing was found. Shouldn't this be mentioned somewhere? Link to comment Share on other sites More sharing options...
eddieone Posted September 21, 2016 Share Posted September 21, 2016 I'm wondering the same. I set static to true on a moving object and it keeps moving. The documentation and support sure are lacking for a paid product. It should be made open source if you ask me. Link to comment Share on other sites More sharing options...
eddieone Posted September 22, 2016 Share Posted September 22, 2016 I'm starting to see box2d is modeled after p2, so if search for how to with p2 bla bla, I find stuff. I know it's a year too late Gyutang, maybe sprite.body.data.ResetMassData(); could help you. Link to comment Share on other sites More sharing options...
trojanfoe Posted September 22, 2016 Share Posted September 22, 2016 There is this, which is old, but probably still holds true. The cleanest solution would appear to be: Quote Keep a buffer of bodies that you want to adjust the velocity of, then after the contact listener callback, run through that list and do what you have to do. Which has got to be better than a timer-based solution as you can do it cheaply and on the next frame. Link to comment Share on other sites More sharing options...
Recommended Posts