# "moveWithCollisions" with havoc?

**URL:** <https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118>\
**Category:** Questions\
**Created:** [April 23, 2023, 1:39am UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118 "2023-04-23T01:39:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [April 23, 2023, 1:39am UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/1 "2023-04-23T01:39:04Z")

</div>

Hey team,

What’s the best method to setup meshes to work simular to “mesh.moveWithCollisions” using Havoc?  
Here i tried something very simple, any key makes the dummy run forward and push the sphere.

> **[Babylon.js Playground](https://playground.babylonjs.com/#Z8HTUN%2339)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

But what if i want the sphere to be static? i give it mass 0 and dummy pass straight through it!  
Same for the ground mesh if i add gravity to the dummy’s velocity, falls straight through the ground mesh 🙂

Any thoughts?

_Edit;_  
Digging a bit further in the docs, it seems because i used `BABYLON.PhysicsMotionType.ANIMATED`…

> **[Babylon.js Playground](https://playground.babylonjs.com/#Z8HTUN%2341)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

So now how could you use `BABYLON.PhysicsMotionType.DYNAMIC` but lock rotations so it doesn’t fall over or anything, just stop moving 🤔

**TLDR;**  
Does Havoc have a method to lock the rotations of a physics body?  
I found this in an old post, @Cedric suggesting a solution for ammojs

> [@Prevent mesh rotation/repositioning on specific axes](https://forum.babylonjs.com/t/prevent-mesh-rotation-repositioning-on-specific-axes/26129/3):
>
> For angular velocity, set all angular speed to 0 so the mesh will not rotate. Ammojs provides
> 
> ```auto
> setAngularFactor
> 
> ```
> 
> that you can call on ammojs rigid body.Or a more ‘manual’ way is to setAngularVelocity to (0,0,0) each frame.

I tried `body.setAngularVelocity(BABYLON.Vector3.Zero())` every frame  
and `body.setAngularDamping(Number.MAX_SAFE_INTEGER)` which seem to be the only angular methods exposed? it did not fix it.

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [April 23, 2023, 3:15pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/2 "2023-04-23T15:15:29Z")

</div>

Okay, so here i used a 6DoF constraint to lock rotations, joint to a small static ground plane… but i feel like it’s a bit hacky 😄  
Also I haven’t quite figured out how to resize or update the shape? since it’s created while the dummy is in T-pose, it’s too wide!

> **[Babylon.js Playground](https://playground.babylonjs.com/#Z8HTUN%2344)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![samuelgirardin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/samuelgirardin/32/87_2.png) [@samuelgirardin](https://forum.babylonjs.com/u/samuelgirardin)\
**Post date:** [April 23, 2023, 3:59pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/3 "2023-04-23T15:59:51Z")

</div>

Hi, maybe you can try to add this in your setup :

_hk.setAngularDamping( dummyAggregate.body,Number.MAX\_SAFE\_INTEGER);_

It seems to work (if I well understand your need ?) : [Physics V2 Simple scene with Aggregate | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#Z8HTUN#49)

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [April 23, 2023, 4:12pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/4 "2023-04-23T16:12:47Z")

</div>

Hi @samuelgirardin  
`setAngularDamping` wont work, it seems to slow the angular velocity down, but the mesh will eventually fall over

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [April 23, 2023, 4:41pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/5 "2023-04-23T16:41:37Z")

</div>

So yeah, from what i’ve gathered, a 6DoF constraint is the only solution at the moment  
To fix the shape, i used a capsule mesh as parent to the dummy, and a capsule physicsShape.  
Next step is moving away from Aggregates to have better control over shapes etc. so i can then avoid the capsule mesh and set the shape size directly.

Result so far;  
_Edit;_ updated to use `scene.onBeforeRenderObservable` for better result in the sample

> **[Babylon.js Playground](https://playground.babylonjs.com/#Z8HTUN%2358)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Raggar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raggar/32/20672_2.png) [@Raggar](https://forum.babylonjs.com/u/Raggar)\
**Post date:** [April 23, 2023, 7:12pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/6 "2023-04-23T19:12:34Z")

</div>

There are a few features like angular locks(Also a Rigidbody character controller) I’ll need as well, before I can port my current project to V2. But I think giving people some time to get used to the new plugin system before adding features is only fair

---

<div class="post-metadata">

**Author:** ![DRLeria](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drleria/32/50928_2.png) [@DRLeria](https://forum.babylonjs.com/u/DRLeria)\
**Post date:** [April 23, 2023, 8:26pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/7 "2023-04-23T20:26:17Z")

</div>

Hi @aWeirdo.  
Today i´ve been playing with Havok.  
I´ve made some updates in your code.

The main thing is create a new Mesh to include your player and use it as PhysicsRoot

[https://playground.babylonjs.com/#Z8HTUN#68](https://playground.babylonjs.com/#Z8HTUN#68)

It´s not perfect but Hope it helps!

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [April 23, 2023, 9:04pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/8 "2023-04-23T21:04:20Z")

</div>

Looks cool! 🙂  
But without a angular lock, something could still knock him over 🙁  
i’m not a huge fan of the box shape, maybe a cylinder?  
and there could be issues with e.g. stairs/sloped meshes,  
both with tipping over and the flat bottom could make it impossible walking upwards/over small obstacles 🤔

---

<div class="post-metadata">

**Author:** ![DRLeria](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drleria/32/50928_2.png) [@DRLeria](https://forum.babylonjs.com/u/DRLeria)\
**Post date:** [April 23, 2023, 10:30pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/9 "2023-04-23T22:30:41Z")

</div>

Totally agree.  
Undoubtedly the option would be to use a Capsule-type Mesh.  
It would be necessary to see another viable solution when going up a ramp or stairs, I remember that there was a post that talked about that issue.  
Also It would be a matter of investigating how to block certain axes to avoid angular rotation.

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [April 23, 2023, 10:44pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/10 "2023-04-23T22:44:48Z")

</div>

With the 6DoF constraint you can define limits,  
here i just blocked all angular axis, probably should remove `BABYLON.PhysicsConstraintAxis.ANGULAR_Y` to allow turning

```
let sixDofJoint = new BABYLON.Physics6DoFConstraint(
    {
        pivotA: new BABYLON.Vector3(0, 0, 0),
        pivotB: new BABYLON.Vector3(0, 0, 0),
        perpAxisA: new BABYLON.Vector3(0, 0, 0),
        perpAxisB: new BABYLON.Vector3(0, 0, 0),
    },
    [
        {
            axis: BABYLON.PhysicsConstraintAxis.ANGULAR_X,
            minLimit: 0,
            maxLimit: 0,
        },
        {
            axis: BABYLON.PhysicsConstraintAxis.ANGULAR_Z,
            minLimit: 0,
            maxLimit: 0,
        },
        {
            axis: BABYLON.PhysicsConstraintAxis.ANGULAR_Y,
            minLimit: 0,
            maxLimit: 0,
        },
    ],
    scene
);

```

I dont know, but hope Havoc have a proper angular lock on physicsBody internally that just haven’t been exposed yet 🙂

---

<div class="post-metadata">

**Author:** ![Raggar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raggar/32/20672_2.png) [@Raggar](https://forum.babylonjs.com/u/Raggar)\
**Post date:** [April 23, 2023, 11:50pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/11 "2023-04-23T23:50:15Z")

</div>

> [@aWeirdo](#):
>
> here i just blocked all angular axis, probably should remove `BABYLON.PhysicsConstraintAxis.ANGULAR_Y` to allow turning

IMO, it’s better to lock all axes and keep a separate variable for the rotation of the model. This way you don’t invalidate contact points by rotating around, although it might be negligible

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [April 24, 2023, 1:34am UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/12 "2023-04-24T01:34:55Z")

</div>

Maybe yeah, keep the physicsBody on a parent of the model so you can rotate the model itself freely 👍

---

<div class="post-metadata">

**Author:** ![Raggar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raggar/32/20672_2.png) [@Raggar](https://forum.babylonjs.com/u/Raggar)\
**Post date:** [April 24, 2023, 11:38pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/13 "2023-04-24T23:38:22Z")

</div>

> **[Babylon.js Playground](https://playground.babylonjs.com/#Z8HTUN%23100)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

```auto
capsuleAggregate.body.setMassProperties({
       inertia: new BABYLON.Vector3(0, 0, 0)
});

```

Manually setting inertia is what we’re looking for

---

<div class="post-metadata">

**Author:** ![DRLeria](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drleria/32/50928_2.png) [@DRLeria](https://forum.babylonjs.com/u/DRLeria)\
**Post date:** [April 24, 2023, 11:58pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/14 "2023-04-24T23:58:45Z")

</div>

Seems logic!! Good job sir 🙌🙌🙌  
 ![IMG_8443](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/6/9644d52b0a92d0e685cf224f4db57bf57d0245ed.jpeg)

---

<div class="post-metadata">

**Author:** ![DRLeria](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drleria/32/50928_2.png) [@DRLeria](https://forum.babylonjs.com/u/DRLeria)\
**Post date:** [April 25, 2023, 2:35pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/15 "2023-04-25T14:35:48Z")

</div>

Working nice!  
Using the Capsule collider and the inertia solution provided by @Raggar

> **[Babylon.js Playground](https://playground.babylonjs.com/#Z8HTUN%23108)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 25, 2023, 2:36pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/16 "2023-04-25T14:36:44Z")

</div>

Works super fine! Congrats 🙂

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 25, 2023, 2:37pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/17 "2023-04-25T14:37:16Z")

</div>

I think I’m not yet used to how powerful Havok is 😃

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [April 25, 2023, 4:15pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/18 "2023-04-25T16:15:43Z")

</div>

Great find!

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [May 2, 2023, 8:24am UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/19 "2023-05-02T08:24:28Z")

</div>

Angular factor is BullerPhysics/Ammojs only.  
Havok provides characterController to do basically what you did but more effectively. It’s a planned feature that will land in Babylon in the coming months.  
Until thenm using this trick is perfectly valid.

---

<div class="post-metadata">

**Author:** ![kuukepe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kuukepe/32/34103_2.png) [@kuukepe](https://forum.babylonjs.com/u/kuukepe)\
**Post date:** [September 8, 2023, 1:45pm UTC](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118/20 "2023-09-08T13:45:22Z")

</div>

@Cedric any news on that Character Controller?

[Next page](https://forum.babylonjs.com/t/movewithcollisions-with-havoc/40118.md?page=2)
