Jump to content

Built in collision - Control sliding?


Puck
 Share

Recommended Posts

Playground demonstrating the issue: https://playground.babylonjs.com/#9JSLE2

Explanation:
I'm trying to create a simple walk around scene and the built in collision system seems to work pretty darn well (Who needs a physics engine anyway?) but I've noticed that when I add any kind of slope the camera will slide down it -- in a real hurry too if gravity is set realistically! I noticed that this doesn't happen with the stairs in the Espilit demo, but looking at the scene file and demo.js I can't figure out how it's managing that. Is there a friction setting or something that I can set for objects like stairs and ramps?

Link to comment
Share on other sites

Hello 

the collision engine uses A LOT of approximation to perform well and thus the gravity cannot be set to a realistic value most of the time. I suggest you set it to a lower value and it should fix your problem :)

Link to comment
Share on other sites

Thanks for replying as always!

So beyond making (possibly significant) adjustments to the collision system there's no real solution? I tried a very small value for gravity (0.03) and still experienced sliding, though the camera does seem to "stick" after sliding a certain amount. Unfortunately it also has the expected side effect of making the camera fall very slowly when walking off an edge.

What I would really like is to be able to set some kind of "sticky" or "friction" value on a per mesh basis that prevents the camera from sliding relative to that object when they are touching. That way I could set sticky for surfaces the player should be able to stand on like stairs, while still allowing sliding for surfaces the player isn't meant to walk on. It would be super useful for moving platforms as well!

I'll take a look at the collision code myself. Advanced math really isn't my forte, but Babylon has a great code base so maybe those parts will be abstracted well enough that I can still muck around with it. :)

Link to comment
Share on other sites

Most of the collision code is here:

https://github.com/BabylonJS/Babylon.js/blob/master/src/Collisions/babylon.collider.ts

and more precisely, you should tweak this function to change the response when a collision occurs:

https://github.com/BabylonJS/Babylon.js/blob/master/src/Collisions/babylon.collider.ts#L360 (something like reducing the length of vel vector)

 

Link to comment
Share on other sites

Perfect. Thank you @Deltakosh! I'm finally gonna fork the engine this evening and take a look at that, as well as properly integrate the Ammo.js plugin I jury rigged. If I come up with anything useful I'll send back a pull request on Github. :) 

Link to comment
Share on other sites

  • 1 month later...

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