Disable collision sliding effect


I add collisions to an ArcRotateCamera in my project. No problem on this side.

I would like to disable the “sliding” effect (If there is a collision, no movement) in some cases.

So, I looked at the Collider class and especially this function :
_getResponse = (pos: Vector3, vel: Vector3), but I can’t get the desired result.

I tried this, but it does not work properly :

    public _getResponse(pos: Vector3, vel: Vector3): void {
        pos.addToRef(vel, this._destinationPoint);
        vel.scaleInPlace(this._nearestDistance / vel.length());

        this._basePoint.addToRef(vel, pos);
        pos.subtractToRef(this.intersectionPoint, this._slidePlaneNormal);
        this._slidePlaneNormal.scaleToRef(this._epsilon, this._displacementVector);


        if (!this.shouldSlide()) return; // ADDED


        this._slidePlaneNormal.scaleInPlace(Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint, this._slidePlaneNormal, this._destinationPoint));

        this._destinationPoint.subtractToRef(this.intersectionPoint, vel);

Can anyone tell me how I could disable this effect?

cc @Cedric

Sliding is by design. You can hack or use another solution.
For example, by comparing the position destination, then call moveWithCollisions and check the destination is what you computed. if it’s not, then there is a collision and you can revert the move.
Another solution is to use mesh intersection : Mesh Intersections | Babylon.js Documentation

And a 3rd possibility is to use a physics engine. But in that case, the physics response (bounced, slide,…) might be hard to determine and revert.


I finally got the result I wanted, so I share how I did it.
My goal was to disable the sliding when the user was zooming only.

My class is inherited from ArcRotateCamera and I override the onCollisionPositionChange function this way:

        const onCollisionPositionChange = this._onCollisionPositionChange;
        this._onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh> = null) => {
            if (collidedMesh && this.ShouldNotSlide()) {
                this._collisionTriggered = false;
                this.radius = Vector3.Distance(this.position, this.target);
            onCollisionPositionChange(collisionId, newPosition, collidedMesh);

If it can help someone,

1 Like