Mesh - Custom movement/Collision checking (Falling/Jumping)

Hello BabylonJS community, i’m new here and trying to learn / understand babylonJS.

What i’m trying to do:

  • I’m trying to create similar movement/collision/jump behaviour like is in for example in hordes.io or WoW.
    Not real or hard physics just simple physic logics
  • Checking collisions (of HeightMap or meshes)
  • Check if object(player mesh is not in ground) and set Falling state (where im stucked with problem)
  • Jump
    • I won’t use moveWithCollision (Im using it but not with ground) with heightMap because this doesnt work correctly with fall / jump and change the movement speed when the ground shape is not straight.

What’s my issue?

  • Well, i tried realy lots of variations and checks, i finished at good position but not good enough collision checking, but still sometimes it stucks or fall underground. In my code theres probably some bad implementations or bad calculations, i would like to show my code to you and if you could give me some advices to go to the correct way to solve this.
  • Issue: While falling it should check the collision and change falling direction due to collision #IMG1
  • I have done this but sometimes it does glitch or just ignore groundMesh and go throu.
  • Issue with Jumping, I do not have idea how to do correct jumping behaviour.

— I does not want you to do code for me, just some advice what should i do / check / what shouldnt i do or if is there a betterway to do it.
Sorry for bad english

Code: https://www.babylonjs-playground.com/#VM3DX3#2

Hi Saqirm, welcome to the forum. Sorry for the slow replies. Lots of programmers have problems in this subject, and I don’t think any perfect solutions exist.

You might want to study rays, and do a few searches for groundMesh’s getHeightAtCoordinates. BUT, that won’t work for measuring heightMap altitude BETWEEN coordinates (a steep ramp). (For force-setting player y-position no matter where upon heightMap.)

I have 3 playgrounds in the “terrain-following” category of my bookmarks:

https://www.babylonjs-playground.com/#21FIRD
https://www.babylonjs-playground.com/#1JXJVF#9
https://www.babylonjs-playground.com/#RBXBG#6 (sps particles)

I don’t know if anything in those… will help you, but maybe.

Babylon.Rays might be worth studying. With lots of “ray shots” around player, constantly, you can use their distance-checking values… to build a custom collision-avoidance system, but it MIGHT be performance-heavy. Not sure… I have never built one. Perhaps not plausible/feasible/practical.

Be sure to check for info by searching our old forum, too.

I hope I have been somewhat helpful. Stay tuned for more comments.

2 Likes

Hey Wingnut, cheers!
Thanks for the reply and some examples’n explanations. I already looked for Rays and your SPS playground. I read that Rays causes performance problems when they are constantly checking the distance. How is it done in MoveWithCollision function, that it is checking the collisions. Is this function also using Rays?

  • I’ll take a look at the rays, probably combine rays with MoveWithCollision might be a good way to do

  • I understand how to do basic movement and keep the groundY, The hardest part is adding to this behaviour checking Collisions (So you cant climb every wall) but this can be done by using groundY in front of (direction) or also using rays. Even harder part is to implicate Jump & Fall.

I made some changes at the night and trying to use CheckCollisions for the ground and seems to be better.
i will provide PG soon

Hello boys, after some tries and tests i updated my movement/collision system and (probably) finished it, now its much more smooth and precise.

If someone would like to see the updated PG here it is: https://www.babylonjs-playground.com/#VM3DX3#5

6 Likes