schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

Custom ID for bodies #260

Closed meyerzinn closed 7 years ago

meyerzinn commented 7 years ago

In the game I'm developing, I have a separate entity ID system. Is there a "supported" mechanism to override the ID of a body, or do I just modify the property and hope for the best?

meyerzinn commented 7 years ago

After re-evaluating my system this is no longer necessary.

schteppe commented 7 years ago

Cool. If someone else looks into this, the answer follows.

Each body has an id property which is used internally in the World to keep track of various things. Therefore it should not be modified.

body.id = 123; // Don't do this

An alternative is to use an own property name:

body.myCustomId = 123; // OK

(If you really want to modify the id property you can set it to an integer before you add it to the world. Make sure the id is unique among the other body id's in the same World)