Jump to content

How to use onCollideObservable method?


Cris
 Share

Recommended Posts

Hi Cris.  I started some demented experiments.  http://www.babylonjs-playground.com/#UP2O8#34

I get some collision observations (watch the console)... but the mesh gets stuck in collision, and then its Y position gets messed-up.

I also changed to .moveWithCollisions.  (line 31)  and set .checkCollisions in lines 57-58. 

Ignore the func in lines 37-52.  That's just me, troubleshooting things... like trying to determine why the mesh gets stuck.  No other progress. Havin' fun, testing things.

I like Deltakosh's idea... better.  It is easy.   But what the heck... playing with collide observers is fun, too.  :)

Let's take Deltakosh's idea further... http://www.babylonjs-playground.com/#UP2O8#37

Now we have orbiting, and free-standing onEntry and onExit funcs, thanks to actionManager's cool ExecuteCodeAction.  Fun!

What's that?  Did somebody in the audience yell "sparticles"?  Ok fine.  http://www.babylonjs-playground.com/#UP2O8#38

Link to comment
Share on other sites

On 2016/11/9 at 8:31 AM, Deltakosh said:

Hello

onCollideObservable is called when using collisions engine (with mesh.moveAndCollide)

You can think about using action managers and use trigger like onIntersectionEnter? http://doc.babylonjs.com/tutorials/How_to_use_Actions

Thx for your help. Now I prepare to use moveWithCollision method, but how to calculate ellipsoid and ellipsoid offset for different meshes?

This problem is puzzling me for several days. I know it should be associated with boundingBox, but I don't know the arithmatic

Link to comment
Share on other sites

On 2016/11/9 at 8:37 AM, Wingnut said:

Hi Cris.  I started some demented experiments.  http://www.babylonjs-playground.com/#UP2O8#34

I get some collision observations (watch the console)... but the mesh gets stuck in collision, and then its Y position gets messed-up.

I also changed to .moveWithCollisions.  (line 31)  and set .checkCollisions in lines 57-58. 

Ignore the func in lines 37-52.  That's just me, troubleshooting things... like trying to determine why the mesh gets stuck.  No other progress. Havin' fun, testing things.

I like Deltakosh's idea... better.  It is easy.   But what the heck... playing with collide observers is fun, too.  :)

Let's take Deltakosh's idea further... http://www.babylonjs-playground.com/#UP2O8#37

Now we have orbiting, and free-standing onEntry and onExit funcs, thanks to actionManager's cool ExecuteCodeAction.  Fun!

What's that?  Did somebody in the audience yell "sparticles"?  Ok fine.  http://www.babylonjs-playground.com/#UP2O8#38

Your demo is amazing! I hava resolved this problem by using moveWithCollision method, thx  @Deltakosh !

But the new problem has occured, how to calculate ellipsoid of ellipsoidOffset for different meshes?

Link to comment
Share on other sites

Hi again Cris, and thanks for the nice words.

Why do you wish to "calculate" ellipsoids or ellipsoid offsets?  Ellipsoids and bounding areas somewhat automatically size and position themselves identically to the mesh.

Camera ellipsoids are narrowed a small amount, by default, I believe.

All in all, I like to turn-on an "ellipsoid viewer".  Know how to do that?  Create a dummy sphere, possibly dummy.showBoundingBox=true, possibly dummy.material.wireframe=true, possibly dummy.visibility=.4. 

And then...  dummy.parent = somemesh, and then... (wait for it...) ...in the renderloop...   dummy.scaling = dummy.parent.ellipsoid;

From there, forward... you should see a wireframe sphere... sort of transparent... you know... a ghost!  Ellipsoid Viewer v1.0 ...by CrisCo Industries Inc.  :)

Then, have fun calc'ing and offsetting.  Calc'ing and offsetting is more fun... when you can SEE the bounding areas.  Ghosts!  :)   Hope this helps.  Good luck and keep us posted.

Link to comment
Share on other sites

Hi Cris.  Actually, you are doing fine, and this is a NICE scene!  Well done! 

Generally, I colored the dummy-sphere red, and made it fatter. And I did some other little tweaks.  But, you did everything quite well... I am impressed!  I think you will be president of a software company, soon.  :o  (yech, eh?)  heh.  Here's a new version:

http://www.babylonjs-playground.com/#1LDA3W#6

Let's tour:

Lines 5-16:  A little tutorial on using arcRotateCamera.  (...in case you were new to those. )

Line 20:  Slow down the mouse wheel speed a bit... easier scene exploring.

Lines 22-40:  Some other cameras to use... as needed.

Line 45:  set a carSpeed variable used in moveWithCollisions and wheel rotations... far below.  NOTE:  Higher car speeds cause collisions to fail.  Not sure why.

Lines 64-69:  Make sure "Plane" has .checkCollisions set true.  It is the wall in front of the car, as you know.

Lines 73-74:  Get a reference to the wheels.

Lines 80-81:  Adjusted ellipsoid size, and did a LITTLE ellipsoidOffset for no reason.  At first, I thought ground and ellipsoid were in constant collision, but that was not a problem.

Lines 89-90:  Remove parenting of dummy to body.  We want to move dummy up/down with sphere.ellipsoidOffset, and parenting to body was preventing that.

Line 93:  Set camera target to body.  Some camera types need this, some don't.

Line 96-97:  Render loop. Here is where we continuously set sphere.position to "track" body.position + body.ellipsoidOffset.  Almost like parenting, but not quite the same.  :)

Lines 101-110: Added backwards move ('A' key) and wheel movements.  I used playground Debug layer => clickable labels... to determine wheel names.  :)

Lines 118-136:  I "broke-out" the event handlers a little bit, and set a scene.onDispose to remove listeners/handlers upon playground scene "un-load".

Okay, this should help a little bit.  Still, there is problems.  Increasing carSpeed  (in line 45) causes collisions to fail.  I don't know why, yet.  Maybe you can determine why, and/or perhaps... others will help us.  Also, collision is happening BEFORE dummy hits wall.  I am not sure why that is happening, either.

Update:  http://www.babylonjs-playground.com/#1LDA3W#7

Above, I added much more carSpeed, and nulled line 99  (the dive-under-wall preventer)  We now see that high carSpeed collision IS happening.  Line 99 anti-dive line... is causing some issues with the #6 playground, it seems. 

Possibly... we should NOT be using car body (with enlarged ellipsoid) for collision testing.  Perhaps, we should have collision testing on car upper disk, lower disk, and both wheels.  Four "separate" collision tests for car. 

When I told you about dummy sphere in my previous post, I did not know you were using a complex model.  Perhaps, multiple car "parts" should have collision testing.  Now I understand what you meant about "calculating" ellipsoid sizes and offsets.  We might need MANY ellipsoid ghosts, eh?  :o

Sorry, sometimes I am not very intelligent, and I have LOW experience with collision stuff.  I will keep thinking and testing.  Talk soon, be well, have fun.

Link to comment
Share on other sites

@Wingnut Thank for your hard work ! 

I found if that body's ellipsoid is set to BABYLON.Vector3(1.2, 0.1,1), the moveWithCollision is work perfect ! But if there have two car , the moveWithCollision will fail. You can see two car has overlay together.

QQ图片20161115164327.jpg

I am making a multiplayer game, and that contains many kinds of car that user can choice, I want to calculate appropriate ellipsoid for different character. But until now , I don't find a better way to set ellipsoid.

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