Jump to content

physic engine


dav74
 Share

Recommended Posts

My results are very strange when i use (other things works very well :) ) :

sphere.applyImpulse(new BABYLON.Vector3(15,0,0),new BABYLON.Vector3(0,0,0));

my mesh goes to the right (all is ok), but after few seconds, it goes to the left !!

 

all my code :

var canvas = document.getElementById("renderCanvas");var engine = new BABYLON.Engine(canvas, true);var scene = new BABYLON.Scene(engine);var camera = new BABYLON.ArcRotateCamera("ArcRotateCamera",0,1.3,100, new BABYLON.Vector3(0, 0, 0), scene);camera.attachControl(canvas);var light = new BABYLON.PointLight("pointLumineux1", new BABYLON.Vector3(100, 100, 0), scene); var ground=BABYLON.Mesh.CreateBox("sol",100,scene);ground.scaling.y=0.001var sphere=BABYLON.Mesh.CreateSphere("sph",20,6,scene);sphere.position=new BABYLON.Vector3(0,4,0);scene.enablePhysics();scene.setGravity(new BABYLON.Vector3(0,-10,0)); sphere.setPhysicsState({ impostor: BABYLON.PhysicsEngine.SphereImpostor, mass: 1 });ground.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0, friction: 0.5, restitution: 0 });sphere.applyImpulse(new BABYLON.Vector3(0,0,15),new BABYLON.Vector3(0,0,0));engine.runRenderLoop(function () {     scene.render(); });

thank you for your help

Link to comment
Share on other sites

dav74,

 

please replace your external ressources links by the following ones:

 

https://rawgithub.com/BabylonJS/Babylon.js/v1.8.0/cannon.js

https://rawgithub.com/BabylonJS/Babylon.js/v1.8.0/babylon.1.8.0.js

 

No '.' between 'raw' and 'github' so the file are served with the right mime type (thanks to the proxy rawgithub.com)

'master' is replaced by 'v1.8.0' so your jsfiddle will work as long as the tag is not deleted on GitHub whereas if the master branch is updated with a new version of babylonJS (babylon.1.8.1.js), the link is not valid anymore.

Link to comment
Share on other sites

i apply impulse to the sphere center (0,0,0). I should have a translation, no ? I think that i haven't understood applyImpulse's use, i'm going to wait documentation or tutorial   :)

 

edit : with no friction on ground, all is ok (i think that i had a "retro effect" (with friction))

 

other question : how to stop the impulse ? (or how long lasts the impulse ?)

 

thank you for your help

Link to comment
Share on other sites

  • 3 months later...

Hello !

I get the same "problem" than Dav.

 

I noticed when you apply a vertical impulse on a sphere like this : sphere.applyImpulse(new BABYLON.Vector3(0,5,0), new BABYLON.Vector3(0,0,0)), there are 2 differents results :

 

- if the sphere is located at (0,0,0) point, all is ok, the sphere jumps and stops.

- if the sphere is elsewhere, like (5,0,0), it jumps and start rolling along x axis.

- if the sphere is elsewhere, like (0,0,5), it jumps and start rolling along z axis.

The speed the sphere is rolling is according to the power of the impulse.

 

I use babylonjs 1.11

Thanks for your feedback :)

Link to comment
Share on other sites

The fact is when I apply an impulse like (0, 5, 0), I just want my sphere to go up, if I want it to go up AND right I have to apply an impulse like (5, 5, 0)

I thought the impulse did not depend of the position of your mesh.

Link to comment
Share on other sites

Hi

 

You are correct, Pouet.  Position of the sphere should not matter.

 

It might be wise to use SOME contact point vector... to ensure a direction.  For a +y impulse... maybe do this.

 

sphere.applyImpulse(new BABYLON.Vector3(0,5,0), new BABYLON.Vector3(0,-.1,0))

 

This puts the impulse contact point UNDER the center of the sphere, and may give you more predictable behavior from the impulse.  In many ways, a contactPoint vector is a direction vector... and a direction vector of 0,0,0 is a un-set and confused vector.  :) It is like asking a sphere to point the way home.  Not much information available.  heh

 

Just a thought.  Good luck.  Please report your discoveries.  Thanks!

Link to comment
Share on other sites

  • 1 month later...

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