Sign in to follow this  
georage

physics: only imposter "sphere" is giving ground collisions?

Recommended Posts

Hello, I am a bit new to this, but have a working hockey rink with a puck and walls that stop the puck, but it seems I cannot use any other impostor shape other than sphere on my puck even though it is defined as a cylinder when created. Thus, the puck ROLLS along the ice instead of sliding like a puck.

Here is a bit of code for the puck and ice.

ice = BABYLON.Mesh.CreateGround('ice', 200, 85, 2, scene);

puck = BABYLON.MeshBuilder.CreateCylinder("puck", {diameter: 0.3, height: 0.1, tessellation: 32}, scene);

...

ice.physicsImpostor = new BABYLON.PhysicsImpostor(ice, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, restitution: iceBouncy, friction: lessSlippery }, scene);

puck.physicsImpostor = new BABYLON.PhysicsImpostor(puck, BABYLON.PhysicsImpostor.CylinderImpostor, { mass: 1, restitution: bouncy, friction: slippery }, scene);

BUT, if I change BABYLON.PhysicsEngine.CylinderImpostor to BABYLON.PhysicsEngine.SphereImpostor it bounces off the ice as expected. Other shapes also do not work. I test with BoxImposter and it did not stop the puck from falling through the ice either.

Is there some reason I can't use CylinderImpostor? I feel this must be something simple I am not doing correctly.

Thanks for any assistance!

EDIT: I am using babylon 2.4 and the latest version of cannon.js

<script src="http://cdn.babylonjs.com/2-4/babylon.js"></script>
<script src="http://www.babylonjs.com/cannon.js"></script>

 

Edited by georage
added versions of babylon and cannon i am using

Share this post


Link to post
Share on other sites

SOLVED: The secret is to not use GROUND mesh for collisions, apparently. Once I defined "ice" as a box mesh it gave me a collision with "cylinder" meshes.

ice = BABYLON.MeshBuilder.CreateBox("ice", {height: 2, width: 200, depth: 85}, scene);

Not sure what ground is useful for if it cannot interact with all mesh types???

 

Share this post


Link to post
Share on other sites

Ummmm ... not sure what you mean but I made a playground. 

http://www.babylonjs-playground.com/#1943IM#1

The problem is that cylinders and other mesh types have to have a minimum height to collide with a ground mesh. In my testing anything under 0.36 cylinder height will fall through a ground mesh, but not a box mesh.

A small box also falls through a ground mesh. 

A small sphere does not fall through a ground mesh.

Of course I may be doing something wrong. My solution was to use a box for a ground mesh (since the ice surface is flat) and increase the size of my cylinder ... which also helped with collision detection it seems. 

 

 

Edited by georage
added more detail

Share this post


Link to post
Share on other sites

Hi @georage, welcome to the forum.  http://www.babylonjs-playground.com/#1943IM#2

Hockey!  YAY!  Love it.

I had to drop the puck from a higher altitude.  Not sure why that changed things, but it did.  Physics engines are weird.  :)

I advanced it a bit further... hope you don't mind.

http://www.babylonjs-playground.com/#1943IM#4

I can't get stick-to-puck collisions working.  Maybe others will have better luck.  I forgot how to do physics, somewhere along the trail.

Share this post


Link to post
Share on other sites

Thanks for looking at it.

That seems like a strange solution, since a hockey puck will drop onto ice from various heights at random times during a game. 

Seems like ice should stop a puck no matter what height you dropped it from.

Cannon seems very flukey with collisions. I've never found a good javascript physics engine outside of C. Do we know if the Energy plugin is going to happen? I'd like to test that one.

 

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

Alright, ya got a big sheet of white ice at the bottom of that last post!  Game on!  hehe  (just having some fun)

http://www.babylonjs-playground.com/#1943IM#5

Tried OimoJS plugin.  (line 65).  Removed the 'new' keyword, and it acts just like CannonJS. (I also changed cylinder imposter to box imposter, just for testing.  Last I knew, Oimo had no cylinderImposter, and changes cylinderImposters into boxImposters internally, anyway, I believe).  

Back to the Oimo version... when we include the 'new' keyword in line 65...

http://www.babylonjs-playground.com/#1943IM#6

...the puck drops at insane speeds, right through the ice, and the sticks drop through, as well. 

hmm.  I have not had much chance to play-with the physics engines interface since it was over-hauled by @RaananW a while ago.  Have you toured his docs?

Fall-thru has been an issue with these physics engines from day 1... and I don't know what the story is.  Head to the web and search for 'physics' along with "through wall" and "through floor".  Lots of people have this issue.  I wish I could help more.  Maybe others will give opinions/comments.  I will keep thinking, too.  If you do more tests, let us know what you discover, please.  thx.

Share this post


Link to post
Share on other sites

Hi gang,

Plane impostor only collides against spheres and particles (if I remember correctly. Sorry, on mobile now).

Cannon has a wonderful collision system, and energy will have it as well ☺. 

Try using a box impostor.

With oimo, try using very large objects (multiply by 100 position and scale). It's an oimo issue which I hope I'll fix soon.

Energy will arrive with 2.5.

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.