moveWithCollisions
causes meshes to slide down slopes when resting (i.e. zero displacement). This is due to gravity, and is expected - for steep slopes. But it would be nice to have a “friction” parameter that scales sliding, potentially to zero on gentle slopes.
It looks like the sliding displacement is calculated in Collider::getResponse
. I tried scaling _slidePlaneNormal
and _displacementVector
, but it didn’t have any effect.
_getResponse(pos, vel) {
pos.addToRef(vel, this._destinationPoint);
vel.scaleInPlace(this._nearestDistance / vel.length());
this._basePoint.addToRef(vel, pos);
pos.subtractToRef(this.intersectionPoint, this._slidePlaneNormal);
this._slidePlaneNormal.normalize();
this._slidePlaneNormal.scaleToRef(this._epsilon, this._displacementVector);
// scaling displacementVector has no noticeable effect (except when scaling to zero)
pos.addInPlace(this._displacementVector);
this.intersectionPoint.addInPlace(this._displacementVector);
this._slidePlaneNormal.scaleInPlace(Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint, this._slidePlaneNormal, this._destinationPoint));
this._destinationPoint.subtractInPlace(this._slidePlaneNormal);
this._destinationPoint.subtractToRef(this.intersectionPoint, vel);
}
I expect it’s more involved than just scaling a vector. If I figure out a solution I’ll post a PG…
Alternatives:
- Use a physics engine.
No, it would break too many things. And it’s too slow on mobile. - Fudge gravity, e.g. scale gravity according to character speed.
This does eliminate sliding, and also solves other issues, like allowing slow-moving characters to climb over curbs and up slopes. It has its own tradeoffs, and it’s a hacky solution anyway, but it has promise.