Jump to content

Newbie on BabylonJS : questions about physics


Tiramitsu
 Share

Recommended Posts

Hi everyone !

 

I started to learn this awesome framework and I focus on the physics engine aspect.

I covering the source and tuts but I have still obviously a lot of questions ! :lol:

 

I use babylon playground but it wont save the code, so here is the convencing part :

var ball = new BABYLON.Mesh('Bob', scene);ball.rotationQuaternion = new BABYLON.Quaternion()ball.position = new BABYLON.Vector3(5.5, 20, 0);var vertex = BABYLON.VertexData.CreateSphere({segments: 20, diameterX: 2, diameterY: 2, diameterZ: 2}); vertex.applyToMesh(ball, true);var ballPhysic = ball.setPhysicsState(BABYLON.PhysicsEngine.SphereImpostor, { mass: 10, friction: 10, restitution: 0.9 });var ground = BABYLON.Mesh.CreateBox('ground', 10, scene);ground.rotationQuaternion = new BABYLON.Quaternion()ground.position = new BABYLON.Vector3(0,-10,0);var groundPhysic = ground.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, { mass: 0, friction: 10, restitution: 0 });ground.translate(BABYLON.Axis.X, -20, BABYLON.Space.WORLD);ground.updatePhysicsBodyPosition();

When I run it, the ball falls to the cube's edge and touch it. But as you can see, i made a translation (the two last lines) and its effective (or rendered at least) after the collision. Why ?

 

With cannon, in the playground,  the compilator says "c.addShape is not a function" and in local, nothing happens.

How use updatePhysicsBodyPosition method ? I can move the object with hacks in the cannon's body object, but I can see the efforts you makes for standardize those tools so...  :)

 

Sure, i miss something ! Sorry...

Have a good day !

Link to comment
Share on other sites

Hi Tiramitsu, welcome to the forum!  Sorry it has taken so long to get a response.

I made a playground for this:  http://playground.babylonjs.com/#YMZ86

I have no solve for this, yet.  Your question:  Why does the translation wait for the ball to collide with the box?  Yes, good question.  Hopefully, the experts will help. 

I also saw a "c.addShape is not a function" error on another recent physics project (when activating Cannon).  I think that will be repaired soon.  The playground always uses the super-latest BJS version, and there's always development happening there.

I have no solutions, sorry.  Maybe this playground demo will let others help more. 

Link to comment
Share on other sites

So!

 

The cannon problem is due to the version of the cannon included in the playground. The cannon plugin was updated and the version should be updated in the playground as well. I see that this is the version hosted from babylonjs.com , @DK - any chance of deploying the other one as well?

 

About the other problem, I will need a little time to understand why it happens, but let's solve this! :-) Working on it.

Link to comment
Share on other sites

Ok. well, this looks like an interesting design problem from Oimo.js, which assumes body should only be updated by the physics engine. Oimo assumes that impulses will be used. 

BUT!

For immobile objects (your box) you could do that - 

http://playground.babylonjs.com/#YMZ86#2 . This will update the box's position correctly.

Maybe this should also be a part of the update function in babylon, I am still trying to find a nicer solution.

 

Another solution (again, for immobile objects) is to simply create a new physics object:

http://playground.babylonjs.com/#YMZ86#3

This works, of course, since the object is reset in its new location.

 

For mobile objects, this will prevent oimo from calculating their physics state correctly in the current frame. So, if the object is moving, let it move and don't update its physics state. In this case it would be better to use impulses.

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