hen Posted August 29, 2016 Share Posted August 29, 2016 Hi, i have a question about the cannon.js integration in babylon. Actually i am working with an authorative server where cannon is running, not using the babylon impostors or any client side physics settings. The server is sending a binary stream via websocket to the client and interpolates the transforms of objects, wich works pretty good so far with the most impostors. My problem is with the terrain transformations of the physics body. I create the shape server side similar like its done in babylon: shape = new CANNON.Heightfield(node.physics.matrix, { elementSize: node.physics.elementSize }); Then trying to solve the transformations to be in sync with the heightfield terrain client side: // quaternion calculated from client mesh var minus90X = new BABYLON.Quaternion(-0.7071067811865475, 0, 0, 0.7071067811865475); var quaternion = mesh.rotationQuaternion.multiply(minus90X); // transforms calculated from client mesh var center; if (mesh.getBoundingInfo) { center = mesh.getBoundingInfo().boundingBox.center; } else { center = mesh.position; } var position = BABYLON.Vector3.Zero(); position.copyFrom(center); var translation = mesh.getBoundingInfo().boundingBox.center.subtract(center).subtract(mesh.position).negate(); position.copyFromFloats(translation.x, translation.y - mesh.getBoundingInfo().boundingBox.extendSize.y, translation.z); // body created using the values above server side var body = new CANNON.Body({ mass: node.physics.mass, material: material, quaternion: quaternion, position: position }); body.addShape(shape); physicsWorld.addBody(body); There must be something i am missing here, because the body transformations are somehow wrong (wich is hard to debug without having a visualization of the physics body). Maybe someone has an idea? Regards Hen Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 29, 2016 Share Posted August 29, 2016 Pinging @RaananW Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 29, 2016 Share Posted August 29, 2016 Hi again, @hen... hope you're well. I just want to clarify. Your scene physics bodies are .position'd wrong? Or .rotationQuat wrong? Or both? Or? The mesh are bouncing off the terrain slopes... incorrectly angled? If it's a problem with angular (orientation/rotation)... then MAYBE it is off-by exactly 90 degrees rotation around some axis? If so, maybe 3 test buttons in the scene. One - adds 90 degrees to physicsBody quat.x, another to add 90 degrees to physicsBody quat.z, etc. Perhaps build yourself a trial'n'error testing scene. Ok, that's the only idea I have. You CAN "watch" a physics imposter... by feeding it's constantly-changing position and quat-rot... TO a standard mesh box... (do it inside the renderLoop). The box will then exactly track the motions of the physics imposter being used on another mesh. It is your "imposter monitoring mesh"... and it would likely be best if it had different colors on each face, or possibly labeled top, bottom, rightside, etc. Also keep in mind that the Quat class on mesh.rotationQuaternion is a BJS Quat class... and the quat on the physics imposter... is a Cannon Quat class. If you build that "imposter monitor box", make sure you have accurate conversion from Cannon quat to BJS quat. Just thoughts. Quote Link to comment Share on other sites More sharing options...
hen Posted August 29, 2016 Author Share Posted August 29, 2016 Hey Wingnut! Thanks! I had to finish some other project wich tooked some time, but now back working on my babylon MMO. I am actually not sure if the problem is with the position or rotation. Its a blackbox, because on the server i see only the position vector and quaternoin values. With my test i added a few spheres to fall down to the terrain. On the client i see them falling correctly but they never collide with the (physical) terrain. Probably im missing something with the transform calculation of the physics body. I will try to stream a rotating terrain now like you mentioned, may that helps to figure out where the problem is. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 29, 2016 Share Posted August 29, 2016 Yeah, that could be .position or .rotation (the ground imposter might be tipped on-edge, so it is difficult for a dropping sphere to hit it.) Perhaps add REAL TALL mountains and DEEP valleys... and drop MANY spheres from random places... see if you can hit the side of a mountain/valley. (indicating a tipped-on-edge ground meshImposter) *shrug* Raanan will visit and have good ideas, soon. He's a genius. Quote Link to comment Share on other sites More sharing options...
hen Posted August 29, 2016 Author Share Posted August 29, 2016 Edit: I solved it Wingnut 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 3, 2016 Share Posted September 3, 2016 Great! Wanna share what the problem was? Quote Link to comment Share on other sites More sharing options...
hen Posted September 5, 2016 Author Share Posted September 5, 2016 On 3.9.2016 at 7:09 PM, RaananW said: Great! Wanna share what the problem was? Sure.. there was no problem within the physics code. It was my fault because one of the properties did not sync right with the physics server. This works really great now, the players, objects, terrain, its all simulated from the authorative server with an interpolated 10fps binary stream. Without to use any headless browser or other hacks. RaananW and Pryme8 2 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted September 6, 2016 Share Posted September 6, 2016 We keep having reoccurring questions about this, maybe for I can finish my current tutorial that will be the next one. There are a ton of different ways to accomplish the effect people are looking for but for the most part the information specifically targeted for it is lacking but if you can fill in the gaps it's there. They did a great job with how bjs handles these calculations and their implementation of different physics systems. And in the announcement thread there was a mention about energy.js. Hopefully we can have some write ups from a few of the guys so we can get topics like these to be a thing of the past. @hen Im stoked you figured it out. Is the 10fps binary stream your limit or are you pushing that. Quote Link to comment Share on other sites More sharing options...
hen Posted September 6, 2016 Author Share Posted September 6, 2016 5 minutes ago, Pryme8 said: We keep having reoccurring questions about this, maybe for I can finish my current tutorial that will be the next one. There are a ton of different ways to accomplish the effect people are looking for but for the most part the information specifically targeted for it is lacking but if you can fill in the gaps it's there. They did a great job with how bjs handles these calculations and their implementation of different physics systems. And in the announcement thread there was a mention about energy.js. Hopefully we can have some write ups from a few of the guys so we can get topics like these to be a thing of the past. @hen Im stoked you figured it out. Is the 10fps binary stream your limit or are you pushing that. This is just the update frequence wich interpolates to 60 fps on the client. I saw the post about energy.js too, wich looks great. Actually cannon.js is the only physics engine that works server side with node.js. Energy could might be an option if they support that too. 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.