Jump to content

Physic Impostor show/debug


tranlong021988
 Share

Recommended Posts

Hi, I'm building my first game with BabylonJS. I have some questions:

this is my game scene (just click and drag drop to navigate): https://dl.dropboxusercontent.com/u/86585940/BabylonWave/index.html 

- Is there any way to show/debug Physics body shape ? it's seem that everybody use showBoundingBox = true but it's only for Box Impostor , my case use Sphere Impostor. 

- I'm using setLinearVelocity to make my "jet" moving and PhysicsImpostor.onCollide to check if "jet" hit the small island, but it's seem that onCollide fired so soon and not sync with physics collision. Console.log show me that onCollide callback fired before "jet" hit the tiny-island. You can check log yourself.  

I'm using version 2.4 beta.

Can anyone help me ? 

Sorry for my porry English. 

 

 

Link to comment
Share on other sites

Hi tranlong, and welcome.

     Unfortunately, I don't think there is any way to see physics impostors.  Cool scene, by the way... I like it!

You have a sphere impostor on the island, and a box impostor on the jetski, and I think they are somewhat too big.  And, I don't think we have impostor.scaling to make them smaller. 

We really need a playground scene to do tests-with.  Have you ever made a playground scene, TL?  What we would want... is a sideways cone (cylinder with small top diameter) with box impostor... to represent the jetski.  And another cone, with sphere impostor, to represent the island.  Then we can do some slow tests in the playground, and see what we discover.

There is another "theory" that could be tried.  Let's imagine 6 small spheres with sphere impostors... "around" the nose of the jetski.  Place them very close together on the front of the jetski, but no overlap.   AND, they cannot be inside of another impostor, so you must remove the box impostor from your jetski.  Instead, put a small box on the back of the jetski, and make it be the parent of the jetski AND the 6 front "bumper".  So, in brief, rear bumper of jetski is parent to 7 things... the jetski model, and the 6 front bumper spheres.

Use the rear bumper box... to do your setLinearVelocity or applyImpulse.  It SHOULD propel all 8 items... because the rear bumper is the parent to all other parts of the jetski.  (maybe)  You might need one more invisible mesh with box impostor... like a board on the bottom of the jetski.  This board might allow you to "jump" the island... with decent physics.  Again, try not to allow any impostors to overlap each other.  (it would be nice if we could SEE them, eh?)

Now set the rear bumper box and the 6 front bumper spheres (and bottom board if you added it)...  .visibility = 0;  Then, see if you get better collisions.  Maybe this will work, maybe not.  :)  Essentially, you are using many little impostors instead of one big impostor.  These little impostors are somewhat adjustable, but... they will not act correctly if you want to make the jetski jump over the island.  This is what the bottom board/impostor will handle... the jetski jump.  It might need to be angled... front higher than back.

We could do good testings in the playground.  If you please, try to make a SIMPLE test scene in the playground where we can do experiments.  Meantime, I will try to figure a way to down-scale the size of impostors... so they don't protrude (stick-out) beyond the edges of uniquely-shaped models... like your jetski.  No promises.  I don't know if impostor down-scaling can be done.  @RaananW , @Temechon, and @Pryme8... are the physics superstars.   Perhaps they will comment... and have other/better ideas.  Keep us posted.  We'll talk again soon.

Link to comment
Share on other sites

hi Wingnut, thank you for detail answer.

I learn a lot from another playground sample but I don't ever try to make a playground sample myself. May be this is the time. I will try to upload my scene to Playground. I don't know if any way to put 3d model from Dropbox to Playground. 

About my case, do you mean that my trouble is an issue of Physics Impostor ? So will jetsky/island model  down-scaling do the trick ? 

I like your idea about using multi Sphere Impostor around jetsky model. Actually, I did use that way for some of my 2d games. I will try this and show you result. 

And again, thank you. 

Link to comment
Share on other sites

My pleasure.

30 minutes ago, tranlong021988 said:

About my case, do you mean that my trouble is an issue of Physics Impostor ? So will jetsky/island model  down-scaling do the trick ?

No.  I was hoping to down-scale the invisible impostor ONLY... without changing the mesh.  By making the impostors smaller, the jetski would need to be closer to the island.... to do onCollide.  But, I don't think we can shrink the impostor.  The impostor is auto-sized by the physics engine.  Not sure how to change or if change would help.  Still thinking.  We need to wait for more comments, too.  Lots of people here... are much smarter than I.  :)

http://doc.babylonjs.com/playground?q=dropbox

There are SOME playgrounds using dropbox (8 of them), but I can't make them work.  Not sure why. 

I use my free github account.  You can drag/drop files onto your account webpage, and commit the files, and there is no limit and no CORS problems.  Here is a playground where I use a .babylon file stored at my free github site.

http://www.babylonjs-playground.com/#1CMD3G#12

Works fine.  :)   Stay in touch, good luck.

Link to comment
Share on other sites

it' seem that I'm out of lucky. I'm using 3D Max as a editor for my scene, add a sphere and export my scene to BabylonJS.

Then I add

var hitPoint = scene.getMeshByName("hitPoint");

hitPoint.parent = jet;

And the sphere disappear. I think it's cause by global to local position, right ? 

Link to comment
Share on other sites

Hi again!  Yes, there is a position shift because of the parenting.  You might try using 3d Max link to create the parent-child relationship before exporting from 3D Max.  I don't have much experience with 3D Max exporting, sorry.  Maybe add and position the spheres AFTER import.  *shrug*

Link to comment
Share on other sites

Hi!

Sorry for a late reply, I am super busy at the moment.

First - regarding physics debugging - it is planned, including joints and collider debugging. I am pretty sure thou that 2.4 won't have it integrated. It'll probably be a 2.5 feature.

About collisions and the onCollide method:

The onCollide method is actually a protected function that is called by the engine itself. to register new collision callbacks, use the physicsImpostor.registerOnPhysicsCollide :

mesh.physicsImpostor.registerOnPhysicsCollide(otherMesh.physicsImpostor, function(collider, collided against) {
    //Do something
});

This way you can set a callback to be executed when the mesh collides against a specific object. The way you did it, setting the onCollide method by yourself, will trigger the callback on each and every collision with other colliders. And you wouldn't know which mesh collided against which other mesh. 

I noticed a few things about your code, I hope it is fine to give the notes here :)

1. You include both cannon and oimo, which is not needed. if you use oimo, leave the cannon.js out of the header, as it is not needed. This won't cause any problem, just longer loading time.

2. you will need to decide whether you use the internal colision system (collisionEnabled = true) or the physics engine. Otherwise you have two collision systems in your game, which wil llead to unwanted results. Unless you did it deliberately, consider removing one of the two. Your collisions right now are from the internal collision system. if it works well, you don't really need the physics engine. Will only confuse you further

3.  the function  updatePhysicsBody () does nothing actually, no need to use it anymore. you can read about it in the physics documentation - http://doc.babylonjs.com/overviews/Using_The_Physics_Engine#bidirectional-transformation-linking

4. I noticed you didn't set gravity (it's 0,0,0). this is fine, of course, but be aware that the physics collisions will work a bit differently than in real life.

Link to comment
Share on other sites

hi Raana, thank you for answering me. 

I set gravity to zero because my game don't have some thing fly up or fall down, just need more accurate collision dectection.

I already find out  .registerOnPhysicsCollide  document before reading your reply. But unfortunately, it still not resolving my trouble. The collission callback fired too soon. But after switching to  BABYLON.CannonJSPlugin(), everything seem fine. Can you tell me what difference between Oimo and Cannon engine ? My target is a mobile mini game (using Intel Crosswalk as runtime wraper), so  which one is capable for performance ? I used to try some samples of BabylonHx, but may be it's too soon to apply for commercial project (it's not stable, I think).   

 

Link to comment
Share on other sites

Oimo and Cannon are two different physics engine. both have the same job - calculate collisions between impostors, they do the job in a different way.

One of the differences is Oimo's simplicity as opposed to Cannon's generous complexity. Oimo has only sphere, box and cylinder colliders. Cannon has a lot more (Convex Hull, Mesh impostor, particles and more fun). Oimo will perform better, usually, but Cannon will be more exact. Not sure what the reason is that cannon works and oimo not, unless you use an impostor cannon has and oimo doesn't.

Link to comment
Share on other sites

13 hours ago, RaananW said:

Oimo and Cannon are two different physics engine. both have the same job - calculate collisions between impostors, they do the job in a different way.

One of the differences is Oimo's simplicity as opposed to Cannon's generous complexity. Oimo has only sphere, box and cylinder colliders. Cannon has a lot more (Convex Hull, Mesh impostor, particles and more fun). Oimo will perform better, usually, but Cannon will be more exact. Not sure what the reason is that cannon works and oimo not, unless you use an impostor cannon has and oimo doesn't.

I just use Sphere - Box Impostor collision. I just guess that it caused by my game size unit. I have a "speed" variable to make jet ski moving . With Oimo, it move faster than within Cannon, for example if speed = 2 with Cannon, jet ski run relevant but with Oimo, it become "tomahawk missile", may be it affect accuration of collision detection(just guess). Anyway, without Physics Body debug/showing, I can not go further. So I just stick with Cannon with better result til now. 

https://dl.dropboxusercontent.com/u/86585940/BabylonWave/index.html   

Link to comment
Share on other sites

  • 1 month later...

are you using a standard collision box? or a model collider? If you are using a standard box, you need to make sure its set to precise (or precision i think its called) mode and it will display a more accurate hitbox around the mesh, otherwise you are just running off the mesh and the bounding box at that point is moot.

There is also a way to increase the number of calculations per frame when you call the plugin i believe it is the second argument you can pass, I have not looked at in months though and forget, but it should be in the documentation.


Then to fully answer your question for if your are using a mesh as the collider, would be to clone the mesh, stick it as a child of the main mesh at Vec3.Zero for the parent, and change its material to a wire frame display, you could then make the wire frame change color on collisions as well to give you a visual trigger, Ive never done this before but that's how I would do it.

If you are using just regular imposters though it is not possible to scale down the box, your only option would be to calculate the alternative mode, you could do a work around... where you stick a invisible mesh inside your object you need to collide, and have it scaled to the size you need and run the collisions on that instead of the main mesh, but if you are dong that then you might as well do a simplified version of your mesh for hit purposes and just do a mesh collider that uses your simplified mesh.

Link to comment
Share on other sites

On 4/27/2016 at 1:08 AM, tranlong021988 said:

I just use Sphere - Box Impostor collision. I just guess that it caused by my game size unit. I have a "speed" variable to make jet ski moving . With Oimo, it move faster than within Cannon, for example if speed = 2 with Cannon, jet ski run relevant but with Oimo, it become "tomahawk missile", may be it affect accuration of collision detection(just guess). Anyway, without Physics Body debug/showing, I can not go further. So I just stick with Cannon with better result til now. 

https://dl.dropboxusercontent.com/u/86585940/BabylonWave/index.html   

the two engines use a different scale factor, I belive Omio is 100 and Cannon is 1

so jetski speed 2:

Omio : 2
Cannon : 0.02

I may be off on this... but its the right direction for an answer to that.

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