diff --git a/src/Marble.hx b/src/Marble.hx index 54756f2b..7fc05830 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -803,7 +803,7 @@ class Marble extends GameObject { if (this.currentUp == null) this.currentUp = new Vector(0, 0, 1); var currentGravityDir = this.currentUp.multiply(-1); - var R = currentGravityDir.multiply(-this._radius); + var R = this.currentUp.multiply(this._radius); var rollVelocity = this.omega.cross(R); var axes = this.getMarbleAxis(); // if (!level.isReplayingMovement) @@ -816,7 +816,7 @@ class Marble extends GameObject { var mv = m.d; mv = mv.multiply(1.538461565971375); - var mvlen = mv.length(); + var mvlen = Math.sqrt(mv.x * mv.x + mv.y * mv.y); if (mvlen > 1) { mv.scale(1 / mvlen); } @@ -836,15 +836,15 @@ class Marble extends GameObject { } var rsq = R.lengthSq(); var crossP = R.cross(motionDir.multiply(desiredYVelocity).add(sideDir.multiply(desiredXVelocity))).multiply(1 / rsq); - desiredOmega.set(crossP.x, crossP.y, crossP.z); - aControl.set(desiredOmega.x - this.omega.x, desiredOmega.y - this.omega.y, desiredOmega.z - this.omega.z); + desiredOmega.load(crossP); + aControl.load(desiredOmega.sub(this.omega)); var aScalar = aControl.length(); if (aScalar > this._angularAcceleration) { aControl.scale(this._angularAcceleration / aScalar); } return false; } - return return true; + return true; } function velocityCancel(currentTime:Float, dt:Float, surfaceSlide:Bool, noBounce:Bool, stoppedPaths:Bool, pi:Array) { @@ -859,7 +859,7 @@ class Marble extends GameObject { var sVel = this.velocity.sub(contacts[i].velocity); var surfaceDot = contacts[i].normal.dot(sVel); - if ((!looped && surfaceDot < 0) || surfaceDot < -SurfaceDotThreshold) { + if ((!looped && surfaceDot < 0.0) || surfaceDot < -SurfaceDotThreshold) { var velLen = this.velocity.length(); var surfaceVel = this.contacts[i].normal.multiply(surfaceDot); @@ -869,7 +869,7 @@ class Marble extends GameObject { } if (noBounce) { - this.velocity = this.velocity.sub(surfaceVel); + this.velocity.load(this.velocity.sub(surfaceVel)); } else if (contacts[i].collider != null) { var otherMarble:Marble = cast contacts[i].collider.go; @@ -894,7 +894,7 @@ class Marble extends GameObject { } contacts[i].velocity.load(otherMarble.velocity); } else { - if (contacts[i].velocity.length() == 0 && !surfaceSlide && surfaceDot > -this._maxDotSlide * velLen) { + if (contacts[i].velocity.length() == 0.0 && !surfaceSlide && surfaceDot > -this._maxDotSlide * velLen) { this.velocity.load(this.velocity.sub(surfaceVel)); this.velocity.normalize(); this.velocity.scale(velLen); @@ -914,7 +914,7 @@ class Marble extends GameObject { vAtC.load(vAtC.sub(contacts[i].normal.multiply(contacts[i].normal.dot(sVel)))); var vAtCMag = vAtC.length(); - if (vAtCMag != 0) { + if (vAtCMag != 0.0) { var friction = this._bounceKineticFriction * contacts[i].friction; var angVMagnitude = friction * 5 * normalVel / (2 * this._radius); @@ -950,7 +950,7 @@ class Marble extends GameObject { } } } while (!done && itersIn < 20); // Maximum limit pls - if (this.velocity.lengthSq() < 625) { + if (this.velocity.lengthSq() < 625.0) { var gotOne = false; var dir = new Vector(0, 0, 0); for (j in 0...contacts.length) { @@ -974,10 +974,10 @@ class Marble extends GameObject { soFar += (dist - outVel * timeToSeparate) / timeToSeparate / contacts[k].normal.dot(dir); } } - if (soFar < -25) - soFar = -25; - if (soFar > 25) - soFar = 25; + if (soFar < -25.0) + soFar = -25.0; + if (soFar > 25.0) + soFar = 25.0; this.velocity.load(this.velocity.add(dir.multiply(soFar))); } } @@ -1049,7 +1049,7 @@ class Marble extends GameObject { slipping = false; } var vAtCDir = vAtC.multiply(1 / vAtCMag); - aFriction = bestContact.normal.multiply(-1).cross(vAtCDir.multiply(-1)).multiply(angAMagnitude); + aFriction = bestContact.normal.cross(vAtCDir).multiply(angAMagnitude); AFriction = vAtCDir.multiply(-AMagnitude); this._slipAmount = vAtCMag - totalDeltaV; } @@ -1076,16 +1076,16 @@ class Marble extends GameObject { friction2 = this._kineticFriction * bestContact.friction; Aadd.load(Aadd.multiply(friction2 * bestNormalForce / aAtCMag)); } - A.set(A.x + Aadd.x, A.y + Aadd.y, A.z + Aadd.z); - a.set(a.x + aadd.x, a.y + aadd.y, a.z + aadd.z); + A.load(A.add(Aadd)); + a.load(a.add(aadd)); } - A.set(A.x + AFriction.x, A.y + AFriction.y, A.z + AFriction.z); - a.set(a.x + aFriction.x, a.y + aFriction.y, a.z + aFriction.z); + A.load(A.add(AFriction)); + a.load(a.add(aFriction)); lastContactNormal = bestContact.normal; lastContactPosition = this.getAbsPos().getPosition(); } - a.set(a.x + aControl.x, a.y + aControl.y, a.z + aControl.z); + a.load(a.add(aControl)); if (this.mode == Finish) { a.set(); // Zero it out } @@ -1699,7 +1699,7 @@ class Marble extends GameObject { if (timeRemaining <= 0) break; - var timeStep = 0.008; + var timeStep = 0.00800000037997961; if (timeRemaining < timeStep) timeStep = timeRemaining; @@ -1841,10 +1841,7 @@ class Marble extends GameObject { } piTime += timeStep; - - if (tdiff == 0 || it > 10) - break; - } while (true); + } while (it <= 10); if (timeRemaining > 0) { // Advance pls if (this.controllable) {