How To Preventing Character Bounce on Flat Terrain?

I’m experiencing an issue with unwanted character bouncing when moving on a terrain generated from a heightmap and I’m using Havok Plugin. The character is controlled using the .setLinearVelocity function, and despite numerous adjustments to the physics body parameters (provided below), the bounce effect persists. I’ve attached a video for reference, and I’m seeking advice on how to prevent this bouncing.

(physics-aggregate player
                 :type :PhysicsShapeType/CAPSULE
                 :mass 50
                 :restitution 0.0
                 :friction 1.0
                 :linear-damping 1.5
                 :angular-damping 0
                 :gravity-factor 1.5
                 :motion-type :PhysicsMotionType/DYNAMIC
                 :mass-props {:inertia (v3 0 0 0)
                              :mass 50})

(create-ground-from-hm "terrain"
                             :texture "img/heightMap.png"
                             :subdivisions 50
                             :width 100
                             :height 100
                             :max-height 10
                             :min-height 0
                             :on-ready (fn [terrain]
                                         (physics-agg terrain
                                                      :type :PhysicsShapeType/MESH
                                                      :friction 0.5
                                                      :restitution 0.0
                                                      :mass 0
                                                      :motion-type :PhysicsMotionType/STATIC)


Hmmm the first thing that I would check is if the dir-vec isn’t pointing too much to the y direction? I tried setting up a similar scenario to yours on a playground, and I’m not seeing the bounce, so there might be a difference there to indicate why it’s happening on your case: Player Capsule movement havok | Babylon.js Playground (

Here I recorded a video of your PG example and it still bounces, when you increase the speed it’s more obvious.

Oh thanks for pointing this, I hadn’t noticed! I tried experimenting a bit more with this setup, and using applyImpulse instead of setLinearVelocity seems to make the bounces less proeminent, but didn’t eliminate them: Player Capsule movement havok | Babylon.js Playground (

I’ll tag @Cedric here who might know of a better way :slight_smile:

I believe the body shouldn’t bounce on a flat surface, regardless of the functions we use

My vision of what’s happening is, when the capsule is moved forwards, its geometry collides with the ground’s triangles at very slight angle, and this influences on the response impulse causing the bounce. If a flat ground with only one subdivision is used (so just two big triangles), I don’t see a bounce. And the reported collision normals only point to the y axis:

But if a flat ground with many subdivisions is used, the bounce happens, and some of the collision normals report a Z axis component:

I may be completely off through, so let’s wait for Cedric :slight_smile:

Yes, exactly. This is how to reproduce the issue. I used the debug physics viewer and noticed that it only happens on every edge. But, I guess it shouldn’t happen, right? At least there should be a work around.

I did some tests with friction/restitution tweaking, then with different shapes for the player (mesh, capsule) and different shapes for the ground.
The only combination without jumps is when the ground is a box. It doesn’t look like an issue on bjs side. But a bug or precision issue with Mesh shape. Have you seen something similar @eoin ?

So this is a bug from Havok Physics?

It might be, we need to check with Eoin. He’s OOF until next week so that’s when we can check.

This could very well be the same issue most physics engines seem so suffer from.
Forces become velocities, and velocities become position displacements. From this new position, whether you use CCD or the more traditional discrete solution, collision detection is performed, and a collision normal is calculated. In this example, you’re looking for a (0,1,0) unit vector, but this might not always be the case. The problem is, that whether you use SAT, GJK, AABBs, OBBs etc. etc. it is custom for collision detection algorithms to use the vector providing the shortest path of penetration to solve the collision. When you hit a triangle like the above case, that shortest path might just as well be on the Z or X axis.
A common approach is to intercept the collision normal, and when a collision with a mesh shape is detected, either recalculate the normal or simply replace it with that of the triangle normal.
I am not sure Havok provides such functionality, though

1 Like

It seems that bouncing does not occur in this Playground. This information is from the following forum post: Havok physics wlaking character bouncing over heightmap - #2 by alexchuber


However, I was unable to identify the difference. Either bouncing occurs, but I am somehow unable to see it.

You’re correct-- that playground still has bouncing! Just less so than that thread’s original playground.

I didn’t try myself, but judging from Cedric’s response here, it seems that tweaking the friction/restitution wouldn’t have fixed the bouncing of that playground anyway. Hmm…

Hi @carolhmj, just wanted to check if @eoin got back and has something to say about this one?

He’s coming back tomorrow.

1 Like

Did you guys have a chance to look at this? Cc @Cedric @eoin

I think @eoin is taking a look at it

1 Like

Is there any GitHub issue or PR that I can track the process?

Raggar and carolhmj are 100% correct. This “bouncing” is simply the outcome of the geometry. When the closest point between the triangle and the capsule is the triangle face, the normal will always point in the direction of the triangle face. However, when the closest point is on the edge, the normal needs to be able to take any value (depending what the other shape is and where it’s located in relation to the edge) and moving quickly towards that edge can result in the bouncing you see.

Erin Catto has a good blog post on this problem (it’s specifically discussing Box2D, but it’s a problem all physics engines have to deal with) if you want more info: Ghost Collisions :: Box2D

We have enabled some additional processing which should fix this for you, if you update your Havok WASM to the latest version (1.1.1).


Thank you! It seems that it’s been resolved with the latest version!