Muribundi Posted August 7, 2018 Share Posted August 7, 2018 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... Quote Link to comment Share on other sites More sharing options...
Guest Posted August 7, 2018 Share Posted August 7, 2018 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 Quote Link to comment Share on other sites More sharing options...
Muribundi Posted August 10, 2018 Author Share Posted August 10, 2018 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 Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 10, 2018 Share Posted August 10, 2018 This is a rather good and intriguing question ? Let s add our Physics Guru to the thread @RaananW Quote Link to comment Share on other sites More sharing options...
RaananW Posted August 10, 2018 Share Posted August 10, 2018 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 Sebavan 1 Quote Link to comment Share on other sites More sharing options...
Muribundi Posted August 12, 2018 Author Share Posted August 12, 2018 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... Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 13, 2018 Share Posted August 13, 2018 @RaananW for follow up ? Thx Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 13, 2018 Share Posted August 13, 2018 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. :) Quote Link to comment Share on other sites More sharing options...
Muribundi Posted August 13, 2018 Author Share Posted August 13, 2018 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... Quote Link to comment Share on other sites More sharing options...
RaananW Posted August 19, 2018 Share Posted August 19, 2018 Hey, would you be able to reproduce a case where, if not running the translate, the impostor doesnt work correctly? would be great to see what you mean and check if it can be fixed. Quote Link to comment Share on other sites More sharing options...
Muribundi Posted August 21, 2018 Author Share Posted August 21, 2018 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.