Jump to content

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


Muribundi
 Share

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...

Link to comment
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

Link to comment
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 :)

 

Link to comment
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...

Link to comment
Share on other sites

Yes, I will try to build a small scene with impostor to show. I doubt it is relate to something special we do on our side, it just seems to happen. Funny thing, I tried with Oimo and Cannon and the same thing happen. The "ball" stop bouncing and start sliding when we remove the two translate calls with identity delta.

We have a static box collider (The Groun) and a dynamic sphere collider (The ball). We give an impulse to the ball, when the ball drop back and hit the plane, it start sliding instead of bouncing. The only difference is in one instance, we do a translate in the afterStep and in the other we don't do it. (So the beforeStep never have the translate) and yes we made sure the delta is always 0,0,0 (I log it if it is not identity)

Do I have a fix no, not for now, because I still haven figured out why it is needed

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...