Jump to content



Recommended Posts

Hello, I'm working on a museum project when you walk in a building and view a bunch of models. I'm trying to do the collision for everything so that when you collide with the models or the museum you stop moving ex like walls in the museum. How was the collision done for Esplit and Windows Cafe? 

Link to comment
Share on other sites

Hi Merfoo!

If you take a look at our Playpen Series Tutorials, you will see one called Collisions By Gravity.  Actually, that tutorial should be titled Camera Collisions... because it covers camera impact with the ground or floor (gravity-based), and camera impact with mesh OTHER THAN ground or floor (inertia-based).

You might want to download the ZIP file that is linked at the bottom of that tutorial, and take a look at the file called collisions.js.  It will give you everything you need. 

Did you know that we are phasing-out the zips that are at the bottom of the tutorials?  I knew you did.  What is to replace them?  The 'playground' !

So, here is a playground for some camera-to-mesh collisions:


Up-arrow your camera right into the box.  BANG!  (ouch)

Want to see your camera fall?

Add this line at the bottom... (you might need to press some ENTER's to make some space)

camera.position.y = 20;

Now hit the playground's RUN button, and then hold up-arrow on your keyboard.  kuh-thud!  :)

Want to see your camera fall much further down?  Then walk off the edge of the floor.  :o

This playground scene is ALMOST the same as the ZIP and ALMOST the same as the default collision playground scene... but I modified it a tiny bit.  I moved the box a little distance, I made the ground bigger, I slowed the camera speed, I removed the pointLight and installed a hemisphericLight (to light-up the dark side of the crate), and then I saved it one too many times.  (There is an unnecessary #2 version too).

But the cool thing about the playground... is that you, YES YOU, MERFOO... can make adjustments to anything, over and over, and watch them happen right now!  Don't worry about SAVE, just adjust, run, adjust, run, have fun! 

Play in the playground in one browser window, read the tutorial in another browser window, and you will be a BabylonJS collisions expert in under 2.73 minutes.  Party On!

Link to comment
Share on other sites

Hello everyone.


(Merfoo, sorry if I'll "kidnap" your topic  :) , but I think it applies to this topic).

Did some one already tried to use octree in collision detection?

I'm trying to shoot a mesh against other mesh, how do i use octree on this?


I already used "dynamicContent.push(mesh)" in all my mesh's (that move) and the octree is beeing updated on the render loop.

Link to comment
Share on other sites

Thank you Wingnut, that helped lot. But if I make the camera position y 30 it doesn't move down, I have to press the arrow key for it to fall. And if I make it 300 and only press the arrow key not hold, it only falls down a little bit. Is it possible for this to not happen and perhaps have the collision be updated constantly or would the performance hit be too great?

Link to comment
Share on other sites

My pleasure.  Your questions/comments are good questions and comments, Merfoo.  I asked myself the same things.  I, personally, would like to see the camera do a complete fall to the ground once the rendering starts (without needing to do arrow keys, as you stated). 


I don't have answers about the performance things.  I am quite a newbie, and have done no significant framework programming.  Let's give this a few days and see if the framework coders and/or other experts... have comments about this.


There are some other options, too.  I know that mesh which have their physicsState set... start falling as soon as the scene starts rendering.  SO... you could make an invisible box, parent the camera to the box, and setPhysicsState on the box (and on the ground and on the scene itself).  That should make the camera start falling as soon as the scene starts rendering. 


Somewhere during the scene building, set a... scene.registerBeforeRender("checkIfOnGround");


Inside checkIfOnGround() function, you might do something like this:


var stopFall = -5;


if (engine.scenes[0].getMeshByName("invisibox").position.y > stopFall) {

     return 1;

} else {





Disposing the invisibox (once IT and the camera are on the ground) should clear the camera.parent property, and allow it to be free of any annoying 'parental hangups'.  :)  But this is a 'work-around' that requires the use of the physics engine.  I am still interested, like you, in the comments of some experts, about doing it WITHOUT the physics engine.


I tried a little "camera nudge" function when I modified that playground test. I set a scene.registerBeforeRender("nudge");   In the nudge function, I tried moving the camera ahead... a few units... to see if I could get the camera to start falling without needing arrow keys.  It didn't work.  :)


In the old Commodore 64 days, we had something called a keyboard buffer (an array), and we could put keypresses into it (such as 5 up-arrow presses)... and the computer would process those keypresses when the program started running.  That would be another possible work-around for us, here, if we were using Commodore 64's.  :)


Ok experts and idea people... let's hear some comments.  (thanks).  Merfoo, if you are doing more experimenting, would you please keep us posted about your discoveries?  Thanks!

Link to comment
Share on other sites

Hey guys.


I didn't test it but it maybe helpfull. It explains how to simulate the "keypressed" event that you are looking for.

Although it's not a good practice.

function simulateKeyPress(character) {jQuery.event.trigger({ type : 'keypress', which : character.charCodeAt(keycodethatyouwant) });}$(function() {$('body').keypress(function(e) {yourfunction();});simulateKeyPress("thekeythatyouwanttobepressed");});
Link to comment
Share on other sites

Interesting, K!  That might have handy applications.  Cool find!


Regarding your comment about octree collisions... umm... you might want to start a new thread about that.  I think it is a topic worthy of its own thread with a proper title.  I know nothing about octree colliding... but you apparently do.  Not many people are working with octrees, I don't think.


As a matter of fact...  http://www.html5gamedevs.com/topic/6877-octrees/#entry41560 is discussing octrees and collisions, and a fresh demo is there, too.  You might want to add more comments onto that thread... and maybe show us what you are working-on.  Are you guys shooting at meshes and having chunks of submesh be removed as you shoot it?  That would be cool.


Make some more posts over there and tell us about it, if you please, eh?  Be well, party on!

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.

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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...