Jump to content

CheckCollisions from inside a box ?


yoric
 Share

Recommended Posts

Hi, setting the "checkCollisions" property to true on a box works well (*) when you're outside the box : http://www.babylonjs-playground.com/#1JVYDS

 

But what if you're inside the box ? 

It looks like you can pass through the box (from inside to outside) : http://www.babylonjs-playground.com/#1JVYDS#1

 

Is there a way to prevent this ?

I'm thinking about using 6 panes instead of a cube, but there might be another solution.

 

* Except you can see through the box.

Link to comment
Share on other sites

Hi yoric!  I can help you with the *

 

You can see through the box at collision-time... because camera collision ellipsoids are set to size 0.5, 1.0, 0.5 by default.  Check this out.

 

http://www.babylonjs-playground.com/#1JVYDS#2

 

Remove line 12 and activate line 14.  Line 14 makes the camera ellipsoid be sized 1.0, 1.0, 1.0, and thus your camera won't be allowed to get close enough to the box... to see through it.

 

On the other subject, I think reddozen has a good idea, and the 6-planes idea is good, too.  A fancy idea would be to monitor the location of the player/camera, and flip the normals appropriately, real-time, with code.  (Most-useful if you're going to have doors/windows in the box, later.)

 

Yoric, if you need assistance coding a "box normals inverter func", just holler.  In brief, all BJS basic shapes have a special class associated with each, called vertexData [src][doc].  On the vertexData object for a mesh, you can find a datatype called "normalsKind".  I do believe you can GET that data, iterate through it to do the invert, and then SET it again.  Make sure your box is created with the "updatable" set to true.

 

There is POSSIBLY another way.  Take a look at this, please. 

 

Check that out. During creation of our box shape, VertexData._ComputeSides is called.  hmmm.   VertexData._ComputeSides is a real new addition to BJS.  Let's go see what that puppy does...  here

 

Holy cow, huh?  Now, if I was a tolerable coder, I would know what all that FRONTSIDE and BACKSIDE (side-orientation) stuff is all about.  I'm not and so I don't.  :D  But, it might be a place for YOU to do experiments with our new _computeSides stuff.  Play-around with that last, optional parameter...

 

Mesh.CreateBox = function (name, size, scene, updatable, sideOrientation)

 

See http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation for more.  (Please pardon the broken links and mixing of italics in there. I'm working my way back to being able to fix them.)  ;)  (inside joke)

 

If you do some experiments with it, please tell us what you learned, afterwards, if you want.  (thx)

 

Hope this helps... be well.

Link to comment
Share on other sites

I guess it comes down to if it's more taxing to detect and flip the normals or keep another box in memory. I like the idea of only having 1 box though. I think I'm going to farm out some of my collision detection to a server engine that isn't limited by javascript. We'll see how it works out if I ever have time to work on anything....

Link to comment
Share on other sites

Hi Yoric. You might want to take a look at this scene I made to turn lights on and off as you move around.

 

Zone Actions

 

There are 4 hidden cubes one for each coloured area. Lights get turned on or off using a mesh collision check.

// On mesh enter actions var setUpZone = function (mesh, light0, light1) {    mesh.actionManager = new BABYLON.ActionManager(newScene);    mesh.actionManager.registerAction(new BABYLON.SetValueAction({ trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: camSensor }, light0, "_isEnabled", true));    mesh.actionManager.registerAction(new BABYLON.SetValueAction({ trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: camSensor }, light1, "_isEnabled", true));    mesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction({ trigger: BABYLON.ActionManager.OnIntersectionExitTrigger, parameter: camSensor },turnoff));   }

As you can see it uses OnIntersectionEnterTrigger and OnIntersectionExitTrigger  to turn the lights On/Off

 

You could start with a visible cube with back face culling set to true, and have the OnIntersectionEnterTrigger  turn back face culling to false on entry and then back face culling to true with the OnIntersectionExitTrigger instead of my light switching

 

Just my thoughts - hope it helps.

 

cheers, gryff :)

 

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