Search code examples
javascriptthree.jsgame-physicscannon.js

How to manually apply gravity on bodies (cannon.js)?


I m looking for a proper way to apply (or disable) gravity on individual objects (without loosing collide events or rotation velocity)

I have read this issue but looking for a more complete answer.

In my case, I want players to have physics applied when bonus boxes wont be affected by gravity but will still fire a onCollide event...

Have you got a clue ?


Solution

  • You just add your object of desire with three. Lets say a gem (box or sphere Mesh) in the normal way it has to be done. Then when you move the player to this position you just fire a event while the player is at the position, delete the object from the scene and give the player what he has collected. So it looks like the player collides with it, but it is not the case and cannon cannot interact with a normal three mesh, you need to bind both together to archive a real collision and gravity to this entity.