reduce bounces when high speed, still not a perfect fix

This commit is contained in:
RandomityGuy 2022-12-24 19:20:38 +05:30
parent f917210f8c
commit 8a677fd2c3

View file

@ -700,7 +700,7 @@ class Marble extends GameObject {
} }
} }
} while (!done); } while (!done);
if (this.velocity.lengthSq() < 625) { // if (this.velocity.lengthSq() < 625) {
var gotOne = false; var gotOne = false;
var dir = new Vector(0, 0, 0); var dir = new Vector(0, 0, 0);
for (j in 0...contacts.length) { for (j in 0...contacts.length) {
@ -717,20 +717,20 @@ class Marble extends GameObject {
var soFar = 0.0; var soFar = 0.0;
for (k in 0...contacts.length) { for (k in 0...contacts.length) {
var dist = this._radius - contacts[k].contactDistance; var dist = this._radius - contacts[k].contactDistance;
var timeToSeparate = 0.1; var timeToSeparate = 0.016;
var vel = this.velocity.sub(contacts[k].velocity); var vel = this.velocity.sub(contacts[k].velocity);
var outVel = vel.add(dir.multiply(soFar)).dot(contacts[k].normal); var outVel = vel.add(dir.multiply(soFar)).dot(contacts[k].normal);
if (dist > timeToSeparate * outVel) { if (dist > timeToSeparate * outVel) {
soFar += (dist - outVel * timeToSeparate) / timeToSeparate / contacts[k].normal.dot(dir); soFar += (dist - outVel * timeToSeparate) / timeToSeparate / contacts[k].normal.dot(dir);
} }
} }
if (soFar < -25) // if (soFar < -25)
soFar = -25; // soFar = -25;
if (soFar > 25) // if (soFar > 25)
soFar = 25; // soFar = 25;
this.velocity = this.velocity.add(dir.multiply(soFar)); this.velocity = this.velocity.add(dir.multiply(soFar));
} }
} // }
return stoppedPaths; return stoppedPaths;
} }