Jump to content

Detect "any ground" collision (from bottom)


yLacaute
 Share

Recommended Posts

Hi !!

I continue to learn this wonderful framework of BabylonJS and program an open source FPS game (should be on Github soon).
I first hesitated between built-in collision system and the cannonjs  physic engine : I tried both and I currently think the physical engine will better suit my needs (rocket jump ! :ph34r::ph34r:). I am already able to move a character, in any direction, first or third camera view, I can jump on objects, but I am facing a new problem....

=> I have to detect ANY ground collision and this task is not so easy as it seems.

Detecting collision with a cube is easy, but detecting collision ONLY from the top of the cube (to end a jump andplay a sound, for example) is more complicated. If I jump, I don't care about wall collision with the cube, I am interested only by the collision when my character collides from bottom.

My character is a simple invisible Box. So I got some ideas :

  • 1) create a second box for my character, a little bit smaller, just to detect collision "from bottom". 
    xxxx  
    xxxx      <=== main box, detect wall collision
    xxxx
     -----        <=== thin bottom box of the character, detect ground collision
     
  • 2) OR change scene objets where I can jump on, with a special "ground type objet" but this solution seems the most awful possible : you are not free anymore to design objects
  • 3) OR change the way collision are detected : for example, if my position.y is decreasing AND THEN my position.y < epsilon, then it means I have collided something. With this solution I don't even need collision event : i create it myself, but it is a little but tricky to code
  • OR ... any idea ?

I will try solution 1 and will share my experience here. If anyone has an advice on this or encountered the same kind of problem plz tell us :) 

Thanks
 

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