yLacaute Posted February 28, 2018 Share Posted February 28, 2018 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 ! ). 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 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted February 28, 2018 Share Posted February 28, 2018 raycast https://doc.babylonjs.com/babylon101/raycasts Quote Link to comment Share on other sites More sharing options...
brianzinn Posted February 28, 2018 Share Posted February 28, 2018 what about this? I think I'm missing something: https://www.babylonjs-playground.com/#YQ7B8L edit: 2nd param in onCollideEvent has object.id === "Ground", so when ground check object.rotation(Quaternion) and you can determine orientation - if ie: character is upright vs. landing on head? adam 1 Quote Link to comment Share on other sites More sharing options...
yLacaute Posted March 1, 2018 Author Share Posted March 1, 2018 hi, @Pryme8 I think I got it, thank you Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.