Jump to content

Phaser Box2d Cannot modify properties of body object


Gyutang
 Share

Recommended Posts

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

  • 9 months later...

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...