applyImpulse - Oimo Vs Cannon

I wanted to create motion like in zero gravity, give impulse to the sphere, add restitution: 1 and completely remove friction, so that the sphere would move indefinitely.

I started with the Oimo engine and everything worked with it exactly as it should - the movement speed remains constant.
But now I use Cannon because I found some bugs in Oimo.

In Cannon, the speed after the impulse begins to fade out gradually until the sphere stops.
How can you fix this?

Those are the limitations of every physics engine. Cannon probably treats collisions a little differently than oimo, even if restitution is 1.

Cannon has the concept of linear and angular damping, which gradually reduces the linear and angular velocity to simulate air friction. is default value is 0.01. you can change it to 0:

Strange behavior | Babylon.js Playground (babylonjs.com)

But it seems like cannon has an internal damping mechanism with collisions as well. The sphere continues to move but still changes the linear velocity on each collision. What you could do is set the linear velocity yourself on each collision, after setting damping to 0. This way the velocity will not change between collisions and you will maintain a constant velocity after collisions.

1 Like

Yes, that’s exactly what I planned and did.

I have a question - which option is more rational to use for collision detection?

In Oimo, I used
trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger

since physicsImpostor.registerOnPhysicsCollide didn’t work with Oimo

Both work with Cannon - which option should you use?

I would guess it is important for you to know that the meshes actually collided - I would use the physics engine’s collision callbacks and not the intersection. on extreme cases the onIntersection event might not trigger (if the physics engine does it’s job 100% correctly it shouldn’t…)

1 Like

Thanks for the answer!
Please tell me where the extended documentation for the Cannon engine is located?
I cannot find information about the options that you used in the example, for example
nativeOptions: {linearDamping: 0, angularDamping: 0}

Hello!

Based on my own experience it’s sometimes just better to stick to one physics engine and use it directly without using BJS physics because some stuff is not implemented in BJS. Yes, you can always use physicsImpostor.executeNativeFunction (the naming makes obvious what it does) and the PhysicsImpostorParameters's interface nativeOptions.

BJS Physics is just another layer of software which can have bugs and can cause unexpected behavior of your physics objects and it’s damned hard to debug these things :stuck_out_tongue: As you can see the onCollissionCallback is only called in Cannon, not impemented in Oimo:

The second thing here is that BJS hides the physics engine implementation which is good and bad at the same time. It’s good because you get an unified interface and naming, you can switch the physics engine anytime but bad at the same time because of the issues I’ve mentioned above and more.

You have to be aware of the details, for example the force thing you try to implement:
(From BJS docs)
Cannon supports both force and impulse (different aspects of the same concept, read about the difference here). Oimo only supports impulses. Applying a force will fallback to impulse.

You try to apply force, but it gets converted to impulse and you don’t even know about it until you realize it’s behaving differently on different physics engines.

Keep them collide! :smiley:
r.

1 Like

Google dude, Google :joy:
https://schteppe.github.io/cannon.js/docs/classes/Body.html

1 Like

Hi @kostiunindima1 just checking in, was your question answered?

as a result, I use a speed adjustment for the sphere after each collision of the sphere with other meshes.
In this way, I achieve the continuous movement of the sphere, as if it were moving in zero gravity.
For collision detection I use the onCollideEvent

1 Like