Sign in to follow this  
Muribundi

object.translate done in PhysicsImpostor.beforeStep and afterStep can't be skip even if there is no translate

Recommended Posts

Hi,

Do anyone know why this operation in the PhysicsImpostor.beforeStep and afterStep can't be skipped even on a translate of 0,0,0

_this.object.translate(_this._deltaPosition, -1);
_this.object.translate(_this._deltaPosition, 1);

When _deltaPosition is 0,0,0 there will be no translation to do, but if I skip it, all the physics stop working correctly. The contact between object are not properly transfered anymore. There is lot of calculation happening in the translate, but I fail the see the point of needing them for the physics.

Take note that as long as one of the two are not skip, everything is fine. Whatever I keep the beforeStep or the afterStep translate, the physics is ok, but if the two are skipped every contact are broken...

Share this post


Link to post
Share on other sites

Hello!

I think there is a misunderstanding here: object.translate does not use physics simulation. It only changes the position property of your mesh: https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.transformNode.ts#L711

Can you provide a repro of what you get in the playground? So we can better understand how to help ;)

Share this post


Link to post
Share on other sites

No it does not use the physics, but it is used by the physics:

/**
 * this function is executed by the physics engine.
 */
this.beforeStep = function () {
    if (!_this._physicsEngine) {
        return;
    }
    _this.object.translate(_this._deltaPosition, -1);

    /*** Other code done in the engine here ***/
};
/**
 * this function is executed by the physics engine.
 */
this.afterStep = function () {
    if (!_this._physicsEngine) {
        return;
    }

    /*** Other code done in the engine here ***/
    
    _this.object.translate(_this._deltaPosition, 1);
};

These two functions come from the babylon side. I made sure that _this._deltaPosition is always at 0,0,0. So normally these two translates should be useless. But they are still needed it seems. Our game is a ball that bounce and if I remove these two functions, the ball do not bounce anymore, it slide on the ground as soon as it touch it and never stop...

But if I keep one of the two, the physics is ok again... (I can remove the one in beforeStep or afterStep it is not important)

The thing is, the translate should do nothing, because it is doing a 0,0,0 translate. But yet it still do, it pass by a lot of "refresh" matrix call to make sure they are up to date... but again why would it need to do that if there is no need for a translate

Share this post


Link to post
Share on other sites

Hi!

If you are asking why it is needed - some objects are not centered, but physics engines don't support it. so, before sttep "centers them" for the physics engine to have the right data, and after step is putting back in place.

To your question (if I understood correctly) - why is it still executed when the delta is 0,0,0? no reason, not needed, you can submit a PR and add me to review and skip this step if it's 0,0,0 :)

 

Share this post


Link to post
Share on other sites

Yeah, that part I figured out, but I'm still trying to figure out why not doing it still break the physics on delta of 0,0,0

It seems something is dirty and refreshed by the translate, but I can't find why... Doing one is enough, this is why I lean toward a needed refresh.

Maybe we do something wrong with the physics, I'm still trying to figure it out...

Share this post


Link to post
Share on other sites

Hi guys.  A quick note, if I may:

IS _this._deltaPosition an AMOUNT, or a worldSpace .POSITION?

IF it IS a worldSpace position... then setting it to 0,0,0 will put the shape-mesh AT that .position... bad thing.  :)

Share this post


Link to post
Share on other sites

It is an amount, a delta... like the name of the variable suggest. It is the difference between mesh center and collision center.

Also, the function is called translate, not set position, so no it will not put it at world center...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.