Jump to content

CannonJS Plugin bug (v2.4)


santarcade
 Share

Recommended Posts

Hi guys,

I upgraded to BabylonJS 2.4 and I think I've found a bug on the CannonJS plugin.

It's line 32 of babylon.cannonJSPlugin.ts:

this.world.step(this._fixedTimeStep, this._useDeltaForWorldStep ? delta * 1000 : 0, 3);

If I leave the default _useDeltaForWorldStep set to true, the game runs 1000 faster than normal, if I set it to false it works fine.

By removing the delta*1000 works as expected, resulting in this patch:

this.world.step(this._fixedTimeStep, this._useDeltaForWorldStep ? delta : 0, 3);

I can't do a PR at the moment, so I'm writing here... but I promise I will be able in the future!

Cheers,

Joez

Link to comment
Share on other sites

Hi Deltakosh,

I double checked: OimoJSPlugin does not have the useDeltaForWorldStep parameter.
I created a small playground that shows the issue: http://www.babylonjs-playground.com/#2B84TV#4

I dug a little in the code, and in addition, I think that this accumulator done with time delta, could suffer on another bug when setting a different timeStep via setTimeStep(timeStep).

Best,
Joez

Link to comment
Share on other sites

Hi RaananW,
you are right: the speed increase factor is not directly 1 thousand.
I wrote some trajectory prediction code to estimate when a body launched with given velocity will hit the ground.

If I keep just delta, the collision will be matching the prediction. If I keep delta*1000, the body will hit the ground way earlier than expected (physics is altered).
This is indeed seen in the playground: same forces on same bodies end up in two different behaviors.

What do you think?
Thank you,
Joez
 

Link to comment
Share on other sites

I've been playing even with setting different timeSteps: if useDeltaForWorldStep is true, after a while it seems the world simulation losses sync (I guess the accumulator jumps in, feeling the need to recover steps).

So far, I have been able to achieve a stable and consistent results changing the line with

this.world.step(this._fixedTimeStep, this._useDeltaForWorldStep ? delta*(this._fixedTimeStep/(1/60)) : 0, 3);

Does it make sense to you?
Best,
Joez
 

Link to comment
Share on other sites

Hi guys,
I tested even OimoJS and my conclusion is that there is definitively something wrong with physics in version 2.4.

Check this demo up: http://www.babylonjs-playground.com/#2B84TV#5

The timeStep in Oimo is inconsistent: so fast to the point that after a few bounces on the plane, the sphere will pass through it.

I tried to check the code, but could not find a reason for this: any idea?

The only consistent version seems to be the first commented line:

var physEngine = new BABYLON.CannonJSPlugin(true);

Joez

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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