private void CalculateVelocity() { Vector3G vector3G = new Vector3G(); double num = (double)Time.time - (double)this.lastVelocityCalc; Character character = base.idMain; Vector3 vector3 = (!character ? base.transform.position : character.origin); Vector3G vector3G1 = new Vector3G(ref vector3); double num1 = 1 / num; vector3G.x = num1 * (vector3G1.x - this.lastPosPrecise.x); vector3G.y = num1 * (vector3G1.y - this.lastPosPrecise.y); vector3G.z = num1 * (vector3G1.z - this.lastPosPrecise.z); Matrix4x4G matrix4x4G = new Matrix4x4G(base.transform.worldToLocalMatrix); Matrix4x4G.Mult3x3(ref vector3G, ref matrix4x4G, out this.localVelocityPrecise); this.lastVelocityCalc = Time.time; this.speedPrecise = Math.Sqrt(this.localVelocityPrecise.x * this.localVelocityPrecise.x + this.localVelocityPrecise.z * this.localVelocityPrecise.z); if (this.speedPrecise >= (double)this.movement.configuration.minMoveSpeed) { double num2 = 1 / this.speedPrecise; this.movementNormalPrecise.x = (double)this.localVelocity.x * num2; this.movementNormalPrecise.y = (double)this.localVelocity.z * num2; double num3 = this.anglePrecise; this.anglePrecise = Math.Atan2(this.movementNormalPrecise.x, this.movementNormalPrecise.y) / 3.14159265358979 * 180; float single = this.movement.configuration.maxTurnSpeed; if (single > 0f && this.anglePrecise != num3 && this.lastAngleSpeedPrecise >= 0.05) { double num4 = (double)Time.deltaTime * (double)single; if (Precise.MoveTowardsAngle(ref num3, ref this.anglePrecise, ref num4, out this.anglePrecise)) { double num5 = this.anglePrecise / 180 * 3.14159265358979; this.movementNormalPrecise.x = Math.Sin(num5); this.movementNormalPrecise.y = Math.Cos(num5); } } this.lastAngleSpeedPrecise = this.speedPrecise; } else { this.speedPrecise = 0; this.movementNormalPrecise.x = 0; this.movementNormalPrecise.y = 0; if (this.lastAngleSpeedPrecise > 0) { float single1 = this.movement.configuration.maxTimeBetweenTurns; float single2 = single1; if (single1 > 0f) { PlayerAnimation playerAnimation = this; playerAnimation.lastAngleSpeedPrecise = playerAnimation.lastAngleSpeedPrecise - (double)(Time.deltaTime / single2); } } } this.lastPosPrecise = vector3G1; this.lastPos = vector3; this.movementNormal = this.movementNormalPrecise.f; this.speed = (float)this.speedPrecise; this.angle = (float)this.anglePrecise; this.localVelocity = this.localVelocityPrecise.f; }
// Token: 0x06000420 RID: 1056 RVA: 0x00014844 File Offset: 0x00012A44 private void CalculateVelocity() { double num = (double)Time.time - (double)this.lastVelocityCalc; global::Character idMain = base.idMain; Vector3 vector = (!idMain) ? base.transform.position : idMain.origin; Vector3G vector3G; vector3G..ctor(ref vector); double num2 = 1.0 / num; Vector3G vector3G2; vector3G2.x = num2 * (vector3G.x - this.lastPosPrecise.x); vector3G2.y = num2 * (vector3G.y - this.lastPosPrecise.y); vector3G2.z = num2 * (vector3G.z - this.lastPosPrecise.z); Matrix4x4G matrix4x4G; matrix4x4G..ctor(base.transform.worldToLocalMatrix); Matrix4x4G.Mult3x3(ref vector3G2, ref matrix4x4G, ref this.localVelocityPrecise); this.lastVelocityCalc = Time.time; this.speedPrecise = Math.Sqrt(this.localVelocityPrecise.x * this.localVelocityPrecise.x + this.localVelocityPrecise.z * this.localVelocityPrecise.z); if (this.speedPrecise < (double)this.movement.configuration.minMoveSpeed) { this.speedPrecise = 0.0; this.movementNormalPrecise.x = 0.0; this.movementNormalPrecise.y = 0.0; float maxTimeBetweenTurns; if (this.lastAngleSpeedPrecise > 0.0 && (maxTimeBetweenTurns = this.movement.configuration.maxTimeBetweenTurns) > 0f) { this.lastAngleSpeedPrecise -= (double)(Time.deltaTime / maxTimeBetweenTurns); } } else { double num3 = 1.0 / this.speedPrecise; this.movementNormalPrecise.x = (double)this.localVelocity.x * num3; this.movementNormalPrecise.y = (double)this.localVelocity.z * num3; double num4 = this.anglePrecise; this.anglePrecise = Math.Atan2(this.movementNormalPrecise.x, this.movementNormalPrecise.y) / 3.1415926535897931 * 180.0; float maxTurnSpeed = this.movement.configuration.maxTurnSpeed; if (maxTurnSpeed > 0f && this.anglePrecise != num4 && this.lastAngleSpeedPrecise >= 0.05) { double num5 = (double)Time.deltaTime * (double)maxTurnSpeed; if (Precise.MoveTowardsAngle(ref num4, ref this.anglePrecise, ref num5, ref this.anglePrecise)) { double num6 = this.anglePrecise / 180.0 * 3.1415926535897931; this.movementNormalPrecise.x = Math.Sin(num6); this.movementNormalPrecise.y = Math.Cos(num6); } } this.lastAngleSpeedPrecise = this.speedPrecise; } this.lastPosPrecise = vector3G; this.lastPos = vector; this.movementNormal = this.movementNormalPrecise.f; this.speed = (float)this.speedPrecise; this.angle = (float)this.anglePrecise; this.localVelocity = this.localVelocityPrecise.f; }
private void CalculateVelocity() { Vector3G vectorg2; double num = Time.time - this.lastVelocityCalc; Character idMain = base.idMain; Vector3 v = (idMain == null) ? base.transform.position : idMain.origin; Vector3G vectorg = new Vector3G(ref v); double num2 = 1.0 / num; vectorg2.x = num2 * (vectorg.x - this.lastPosPrecise.x); vectorg2.y = num2 * (vectorg.y - this.lastPosPrecise.y); vectorg2.z = num2 * (vectorg.z - this.lastPosPrecise.z); Matrix4x4G b = new Matrix4x4G(base.transform.worldToLocalMatrix); Matrix4x4G.Mult3x3(ref vectorg2, ref b, out this.localVelocityPrecise); this.lastVelocityCalc = Time.time; this.speedPrecise = Math.Sqrt((this.localVelocityPrecise.x * this.localVelocityPrecise.x) + (this.localVelocityPrecise.z * this.localVelocityPrecise.z)); if (this.speedPrecise < this.movement.configuration.minMoveSpeed) { float num3; this.speedPrecise = 0.0; this.movementNormalPrecise.x = 0.0; this.movementNormalPrecise.y = 0.0; if ((this.lastAngleSpeedPrecise > 0.0) && ((num3 = this.movement.configuration.maxTimeBetweenTurns) > 0f)) { this.lastAngleSpeedPrecise -= Time.deltaTime / num3; } } else { double num4 = 1.0 / this.speedPrecise; this.movementNormalPrecise.x = this.localVelocity.x * num4; this.movementNormalPrecise.y = this.localVelocity.z * num4; double anglePrecise = this.anglePrecise; this.anglePrecise = (Math.Atan2(this.movementNormalPrecise.x, this.movementNormalPrecise.y) / 3.1415926535897931) * 180.0; float maxTurnSpeed = this.movement.configuration.maxTurnSpeed; if (((maxTurnSpeed > 0f) && (this.anglePrecise != anglePrecise)) && (this.lastAngleSpeedPrecise >= 0.05)) { double maxDelta = Time.deltaTime * maxTurnSpeed; if (Precise.MoveTowardsAngle(ref anglePrecise, ref this.anglePrecise, ref maxDelta, out this.anglePrecise)) { double a = (this.anglePrecise / 180.0) * 3.1415926535897931; this.movementNormalPrecise.x = Math.Sin(a); this.movementNormalPrecise.y = Math.Cos(a); } } this.lastAngleSpeedPrecise = this.speedPrecise; } this.lastPosPrecise = vectorg; this.lastPos = v; this.movementNormal = this.movementNormalPrecise.f; this.speed = (float)this.speedPrecise; this.angle = (float)this.anglePrecise; this.localVelocity = this.localVelocityPrecise.f; }