From 8a677fd2c36a3569feccbf69c14c4bc680bae503 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sat, 24 Dec 2022 19:20:38 +0530 Subject: [PATCH] reduce bounces when high speed, still not a perfect fix --- src/Marble.hx | 58 +++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Marble.hx b/src/Marble.hx index 782f0d2b..3c87508f 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -700,37 +700,37 @@ class Marble extends GameObject { } } } while (!done); - if (this.velocity.lengthSq() < 625) { - var gotOne = false; - var dir = new Vector(0, 0, 0); - for (j in 0...contacts.length) { - var dir2 = dir.add(contacts[j].normal); - if (dir2.lengthSq() < 0.01) { - dir2 = dir2.add(contacts[j].normal); - } - dir = dir2; - dir.normalize(); - gotOne = true; - } - if (gotOne) { - dir.normalize(); - var soFar = 0.0; - for (k in 0...contacts.length) { - var dist = this._radius - contacts[k].contactDistance; - var timeToSeparate = 0.1; - var vel = this.velocity.sub(contacts[k].velocity); - var outVel = vel.add(dir.multiply(soFar)).dot(contacts[k].normal); - if (dist > timeToSeparate * outVel) { - soFar += (dist - outVel * timeToSeparate) / timeToSeparate / contacts[k].normal.dot(dir); - } - } - if (soFar < -25) - soFar = -25; - if (soFar > 25) - soFar = 25; - this.velocity = this.velocity.add(dir.multiply(soFar)); + // if (this.velocity.lengthSq() < 625) { + var gotOne = false; + var dir = new Vector(0, 0, 0); + for (j in 0...contacts.length) { + var dir2 = dir.add(contacts[j].normal); + if (dir2.lengthSq() < 0.01) { + dir2 = dir2.add(contacts[j].normal); } + dir = dir2; + dir.normalize(); + gotOne = true; } + if (gotOne) { + dir.normalize(); + var soFar = 0.0; + for (k in 0...contacts.length) { + var dist = this._radius - contacts[k].contactDistance; + var timeToSeparate = 0.016; + var vel = this.velocity.sub(contacts[k].velocity); + var outVel = vel.add(dir.multiply(soFar)).dot(contacts[k].normal); + if (dist > timeToSeparate * outVel) { + soFar += (dist - outVel * timeToSeparate) / timeToSeparate / contacts[k].normal.dot(dir); + } + } + // if (soFar < -25) + // soFar = -25; + // if (soFar > 25) + // soFar = 25; + this.velocity = this.velocity.add(dir.multiply(soFar)); + } + // } return stoppedPaths; }