Jump to content

CannonJS, high velocity sphere and no collision detection


bfarisdev
 Share

Recommended Posts

Hi there!

I'm creating a game that currently uses a simple physics based system. A sphere is controlled by the player and moves around a world (ground generated with a heightmap). Everything works perfect until the ball falls from a very tall height. The collision detected stops working and the ball falls right through the ground due to the high velocity.

Here is the code associated with the objects:

var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: 1}, scene);
sphere.physicsImpostor = new BABYLON.PhysicsImpostor(sphere, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 1, restitution: 0.3 }, scene);
var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "./res/height6.png", worldSize, worldSize, 200, 0, 50, scene, false, function () {
    ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground, BABYLON.PhysicsImpostor.HeightmapImpostor, { mass: 0 });
});


I was wondering if someone can point me in the right direction for how I should go about solving this behavior. It is necessary that the collision detection works for high velocity collisions in my game.

Best regards,
Brian

Link to comment
Share on other sites

Welcome to the forum!

I think you are using collision frame detection and you need continuous (predictive) collision detection.  In other words, when the frame before and after the actual collision render, there are no collisions.  I'm not sure how to answer your question as you are using a heightmap.  Some people have made thicker ground or changed the world dimensions, but I don't think that will address high velocity heightmap.  Hopefully somebody else has a solution. Which physics engine are you using?  I think cannonJS has support for that at least on certain Impostors - we may need a PG (Playground).

Link to comment
Share on other sites

Hello! I felt into this problem some times ago. The best option is to make your ground thicker (like give it some height instead of using a pure plane)

Other option is to set the scene.getPhysicsEngine().setTimeStep(1 / 120) to make it more precise

Link to comment
Share on other sites

2 hours ago, Deltakosh said:

Hello! I felt into this problem some times ago. The best option is to make your ground thicker (like give it some height instead of using a pure plane)

Other option is to set the scene.getPhysicsEngine().setTimeStep(1 / 120) to make it more precise

Setting the timestep worked perfectly! :)

For others that do not have luck, can you post the function for increasing the ground thickness? (I've tried ground.depth with no luck and didn't see an imposter thickness function. Height seems to only adjust the elevation).

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