Posted April 05, 2022 by kindeyegames
A simple example integrating 3DObject with cannon-es.js (javascript 3D physics library.)
Since C3 does not have a 3D physics/collision system, we can leverage an external library to implement it.
The example includes joining a 3DObject and a cannon body together through a new 3DObject scripting interface:
setCannonBody(body, setRotation) - body: a reference to a cannon body - setRotation: boolean
If setRotation is true, the 3DObject rotates with the rotation of the cannon body.
The 3DObject will follow the cannon body's x,y,z location and rotation. No other C3 events are required, the location and rotation are set for the 3DObject every tick.
The example also includes setting a 3DObject position and cannon body position based on a C3 sprite orbiting a point (it does not set the rotation of the cannon body, so collision may be a little off. I leave this an exercise for the reader.)
The cannon-es.js library is pretty nice and very comprehensive. It can also do things like call functions on collision (addListener('collision', ...) ), etc. This can be integrated with C3 through JS scripting
Currently, I don't plan on working on a cannon-es.js plug-in/behavior for C3, however, I am very willing to help with any 3DObject integration with such a plug-in in case another developer creates one.