Jump to content

how to use cannonjsplugin


Recommended Posts

Hi jiweigang1 and others.  Here is a playground scene loosely based upon that demo... http://www.babylonjs.com/playground/#1QOY2K .  It works just awful. 


I greatly lowered the restitution numbers, I turned off the shadows, and tried numerous other things, and it did not improve.  Oh well, ya can't win 'em all.  :)  I am certainly no expert with the physics engine, and my playground demo blatantly proves it. :o


Sorry jiweigang1.  I tried to be helpful and I failed with style and grace.  Maybe if you use the Get .zip button and download a copy to your home, it will work better, there.  Maybe not.  I am going to try to determine why the restitution (mesh bounce) is being so powerful.

Link to comment
Share on other sites

Hi j


    I am a bit busy today, but maybe try babylon.js version 1.11.0 .  *shrug*  If you don't have a copy of 1.11.0, you can find one in this zip...




And please report your discoveries.  Thanks.


Here is another possibly-useful zipped demo.




It uses a fire button and a slide button.  You can click either, as fast as you want.  It is sort of a applyImpulse test scene... and it uses a babylon.js version 12 beta from sometime in May.  It is also published on-line at http://urbanproductions.com/wingy/babylon/polygun/yerzhik/polygun04_yer.htm


Good luck.

Link to comment
Share on other sites

Did you view the playground scene, DK?  I see powerful restitution happening the whole time, not just during start.  And the restitution numbers on floor, walls, spheres, and boxes... are set very low.  0.1 on the walls and floor, 0.3 on the spheres and boxes. Yet I show almost all the physics objects... shot into outer space... in under 1 minute, IE or FF30.


But you know me. :)  I bet I made a mistake somewhere in that playground scene.  http://www.babylonjs.com/playground/#1QOY2K


(Its probably the same pg scene that j1 will show you in his/her new thread).  If it isn't one collision issue, its another.  :)

Link to comment
Share on other sites



I see a strange thing.


Move the scroller UP/DOWN on the editor quickly while the sphere is bouncing... then the sphere gets very bouncy.  So it seems... when the CPU is very busy... the physics engine ignores its restitution settings.  Interesting.


Maybe I should just get out of the way, and let you two handle this.  :)


Update:  I'm seeing inconsistencies.  A few minutes ago, I ran #1QOY2K#3 and #1QOY2K, and they acted perfect.  On #1QOY2K, the spheres fell to the floor and didn't bounce much... just rolled off to the sides (perfect per the low restitution values).  Then, moments ago, I ran it again, and back to super-bounce.  *scratch scratch*  hmm.  weird!

Link to comment
Share on other sites

I dunno, Captain Koshenheimer.  :)  http://www.babylonjs.com/playground/#1QOY2K#5 is still looking quite flakey.


*scratch scratch*  And it looks more flakey when you slide the editor scrollbar up and down, too.  I dunno.  In that retarded demo where I emit physics-active boxes from a particleSystem...




...we don't see mesh flying off into outer space.  How many physics objects are spawned in the same location on THAT thing?  Tons.


But you are rarely wrong about these things... so I have to roll with your words. :)  Yet something still tells me that something has changed somewhere.

Link to comment
Share on other sites

Hi DK.  So you are saying that the differences in b.prototype._collideWithWorld that J1 showed us in that picture (post #12)... does not affect physics collisions? 


*nod*  Thanks for that info.  If the physics engine collisions have gone wonky, other people who are using legacy code... will start reporting powerful restitutions... after they update to newer versions of the framework.  Better said... we'll see if others have problems with this in the future.  :)


I am no expert on ANYTHING, but, collisions seems like it would be difficult to code.  For example, ground.checkCollisions = true;  ... is used for TWO types of collisions.  One type, colliding with a physics imposter, and the other type, colliding with a standard mesh or camera ellipsoid. 


Tangent:  And there are two types of gravity,  scene gravity and physics engine gravity (physics engine gravity can over-ride scene gravity).  *scratch scratch*  So, a person could set scene.enablePhysics(some gravity), and then later set scene.disablePhysicsEngine()... and then the normal scene gravity would again be the dominant one?  Weird.  And why is the word 'Engine' on the end of scene.disablePhysicsEngine()?  Shouldn't it be just scene.disablePhysics()?  Like we need yet another inconsistency.  heh.  Who names these functions?  :)


Back on subject:  You see, when working with Dad72 and his camera ellipsoid causing collisions with the ground, maybe something you did with that problem... affected the physics collisions.  I know its more complicated than I can understand, but, isn't a camera ellipsoid... in some way... just a different type of physics imposter? 


Was the reason for .moveWithCollisions()... so that an object that had a setPhysicsState... COULD be moved AT ALL (without using applyImpulse)?


In Dad72's issue, it seemed that he was mixing ellipsoid collisions... with physics collisions (understandably). 


I don't know.  It just seems that... when an adjustment gets made to anything 'collision'... it COULD affect both standard collisions AND physics collisions.  Or maybe not.  Thank God that I don't code FPS games or webGL frameworks.  :)  (I don't have enough brain power for either, actually).  :)


DK, if you say that your recent adjustments to collisions... does not affect physics collisions, I will certainly accept that as truth.  But I can't speak for jiweigang1, even though I have stuck my nose right in the middle of his/her business, here.  :)


I like the physics in BJS... its my friend.  We have played together and had lots of fun.  I want it to stay healthy.  heh

Link to comment
Share on other sites

I use moveWithCollisions to move a character to animate. and I add a ELIPSOID this player (as we would with the camera) thanks DK for this.

My character is now control with the keyboard and detects collisions with objects in the scene and receives gravity with the ground. I am no longer require the use of a ground flat.

I also add octree to optimize collisions and mesh of the scene (static and dynamic) and the result is that the scene is in the 57 FPS with a lot of things above (shadows, collision, objects, animation. ..)

I thus uses more physical for it, because the goal is to use the least possible (physics is greedy).

Link to comment
Share on other sites

Ah, thanks for the info, Dad72.  By the way, http://castorengine.com/babylon/collision/ works nice.  Your player looks good walking across hilly ground.  Well done!


Okay, other readers of this physics engine topic... Dad72's issue did not involve the physics system.  I thought it did, but I was mistaken (not unusual for me).  :)

Link to comment
Share on other sites

This is important to understand: Collisions engine and physics engine are different engines. Nothing is share between them


Collisions is for collisions check and response between a mesh and an ellipsoid (for the freeCamera mainly and now for mesh with ellipsoid over them). I try to keep this engine smooth and optimized (See updates I made in Octrees for instance)


Physics is for physics simulation using a plugin (Only Cannonjs for now) which simulates reality-like interactions between basics shapes

Link to comment
Share on other sites

Thanks!  But, mesh.checkCollisions is common to both engines, yes? 


Let's say you enable physics in a scene, then setPhysicsState on a sphere and ground (both with .checkCollsions set true, and both with some restitution >0).  Then make the sphere be the parent of an ellipsoid-set camera that has camera.checkCollsions set true. 


Now drop the sphere/camera from above... onto the ground.  Which engine takes priority?  Do you process the sphere imposter colliding with the ground, or the camera ellipsoid colliding with the ground?  Parent always wins?


And then, what if scene.gravity is set 0, -9, 0, but physics engine gravity is set 0, -2, 0?  Which has priority?  The camera is going to try to fall faster, but its parent sphere won't let it.  The camera will not want to bounce (it hasn't got its physicsState set, and its not possible to have it set), but its parent will try to make it bounce.  Parent wins?


I suppose I should just do some experiments and stop bothering management, huh?  :)

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.

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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...