private void StepPhysics(float deltaTime) { bool flag; Vector3 vector3 = new Vector3(); Vector3 vector31 = new Vector3(); Vector3 vector32 = new Vector3(); Vector3 vector33 = new Vector3(); float single; Vector3 vector34; Vector3 vector35 = new Vector3(); Vector3 vector36 = new Vector3(); bool flag1; Vector3 vector37 = this.movement.velocity; Vector3 vector38 = this.movement.acceleration; this.ApplyInputVelocityChange(deltaTime, ref vector37, ref vector38); this.ApplyGravityAndJumping(deltaTime, ref vector37, ref vector38, out flag); if (this.movingWithPlatform) { Vector3 vector39 = this.movingPlatform.activePlatform.TransformPoint(this.movingPlatform.activeLocal.point); vector3.x = vector39.x - this.movingPlatform.activeGlobal.point.x; vector3.y = vector39.y - this.movingPlatform.activeGlobal.point.y; vector3.z = vector39.z - this.movingPlatform.activeGlobal.point.z; if (vector3.x != 0f || vector3.y != 0f || vector3.z != 0f) { this.ApplyMovementDelta(ref vector3, 0f); } Quaternion quaternion = this.movingPlatform.activePlatform.rotation * this.movingPlatform.activeLocal.rotation; Quaternion quaternion1 = quaternion * Quaternion.Inverse(this.movingPlatform.activeGlobal.rotation); float single1 = quaternion1.eulerAngles.y; if (single1 != 0f) { this.ApplyYawDelta(single1); } } vector31.x = vector38.x * deltaTime; vector31.y = vector38.y * deltaTime; vector31.z = vector38.z * deltaTime; Vector3 vector310 = this.tr.position; if (!flag) { vector32.x = vector37.x * deltaTime; vector32.y = vector37.y * deltaTime; vector32.z = vector37.z * deltaTime; vector33.x = vector310.x + vector32.x; vector33.y = vector310.y + vector32.y; vector33.z = vector310.z + vector32.z; } else { vector33.x = vector310.x + deltaTime * (this.movement.velocity.x + vector31.x / 2f); vector33.y = vector310.y + deltaTime * (this.movement.velocity.y + vector31.y / 2f); vector33.z = vector310.z + deltaTime * (this.movement.velocity.z + vector31.z / 2f); vector32.x = vector33.x - vector310.x; vector32.y = vector33.y - vector310.y; vector32.z = vector33.z - vector310.z; } float single2 = this.cc.stepOffset; float single3 = single2 * single2; float single4 = vector32.x * vector32.x + vector32.z * vector32.z; single = (single4 <= single3 ? single2 : Mathf.Sqrt(single4)); if (this._grounded) { vector32.y = vector32.y - single; } this.movingPlatform.hitPlatform = null; this._groundNormal = new Vector3(); float single5 = this.input.crouchSpeed * deltaTime; CCTotem.MoveInfo moveInfo = this.ApplyMovementDelta(ref vector32, single5); this.movement.collisionFlags = moveInfo.CollisionFlags; float wantedHeight = moveInfo.WantedHeight - moveInfo.PositionPlacement.height; CollisionFlags collisionFlags = moveInfo.CollisionFlags | moveInfo.WorkingCollisionFlags; flag1 = (this.input.crouchSpeed <= 0f || (collisionFlags & CollisionFlags.Above) != CollisionFlags.Above ? false : wantedHeight > this.movement.setup.maxUnblockingHeightDifference); this.movement.crouchBlocked = flag1; this.movement.lastHitPoint = this.movement.hitPoint; this._lastGroundNormal = this._groundNormal; if (this.movingPlatform.setup.enable && this.movingPlatform.activePlatform != this.movingPlatform.hitPlatform && this.movingPlatform.hitPlatform != null) { this.movingPlatform.activePlatform = this.movingPlatform.hitPlatform; this.movingPlatform.lastMatrix = this.movingPlatform.hitPlatform.localToWorldMatrix; this.movingPlatform.newPlatform = true; } if (this.movement.collisionFlags == CollisionFlags.None) { vector34 = vector33; this.movement.velocity = vector37; this.movement.acceleration = vector38; } else { this.movement.acceleration.x = 0f; this.movement.acceleration.y = 0f; this.movement.acceleration.z = 0f; vector35.x = vector37.x; vector35.y = 0f; vector35.z = vector37.z; vector34 = this.tr.position; this.movement.velocity.x = (vector34.x - vector310.x) / deltaTime; this.movement.velocity.y = (vector34.y - vector310.y) / deltaTime; this.movement.velocity.z = (vector34.z - vector310.z) / deltaTime; vector36.x = this.movement.velocity.x; vector36.y = 0f; vector36.z = this.movement.velocity.z; if (vector35.x != 0f || vector35.z != 0f) { float single6 = (vector36.x * vector35.x + vector36.z * vector35.z) / (vector35.x * vector35.x + vector35.z * vector35.z); if (single6 <= 0f) { this.movement.velocity.x = 0f; this.movement.velocity.z = 0f; } else if (single6 < 1f) { this.movement.velocity.x = vector35.x * single6; this.movement.velocity.z = vector35.z * single6; } else { this.movement.velocity.x = vector35.x; this.movement.velocity.z = vector35.z; } } else { this.movement.velocity.x = 0f; this.movement.velocity.z = 0f; } if (this.movement.velocity.y < vector37.y - 0.001f) { if (this.movement.velocity.y >= 0f) { this.jumping.holdingJumpButton = false; } else { this.movement.velocity.y = vector37.y; } } } if (this._grounded != this._groundNormal.y > 0.01f) { if (!this._grounded) { this._grounded = true; this.jumping.jumping = false; if (this.jumping.startedJumping) { this.jumping.startedJumping = false; this.jumping.lastLandTime = Time.time; } this.SubtractNewPlatformVelocity(); if (this.sendLandMessage) { this.RouteMessage("OnLand", SendMessageOptions.DontRequireReceiver); } } else { this._grounded = false; if (this.movingPlatform.setup.enable && (this.movingPlatform.setup.movementTransfer == CCMotor.JumpMovementTransfer.InitTransfer || this.movingPlatform.setup.movementTransfer == CCMotor.JumpMovementTransfer.PermaTransfer)) { this.movement.frameVelocity = this.movingPlatform.platformVelocity; this.movement.velocity = this.movement.velocity + this.movingPlatform.platformVelocity; } if (this.sendFallMessage) { this.RouteMessage("OnFall", SendMessageOptions.DontRequireReceiver); } vector34.y = vector34.y + single; } } if (this.movingWithPlatform) { this.movingPlatform.activeGlobal.point.x = vector34.x; float single7 = vector34.y; Vector3 vector311 = this.cc.center; this.movingPlatform.activeGlobal.point.y = single7 + (vector311.y - this.cc.height * 0.5f + this.cc.radius); this.movingPlatform.activeGlobal.point.z = vector34.z; this.movingPlatform.activeLocal.point = this.movingPlatform.activePlatform.InverseTransformPoint(this.movingPlatform.activeGlobal.point); this.movingPlatform.activeGlobal.rotation = this.tr.rotation; this.movingPlatform.activeLocal.rotation = Quaternion.Inverse(this.movingPlatform.activePlatform.rotation) * this.movingPlatform.activeGlobal.rotation; } this.BindCharacter(); }
private void ApplyGravityAndJumping(float deltaTime, ref Vector3 velocity, ref Vector3 acceleration, out bool simulate) { Vector3 vector3 = new Vector3(); float single; float single1 = Time.time; if (!this.input.jump || !this.canControl) { this.jumping.holdingJumpButton = false; this.jumping.lastButtonDownTime = -100f; } if (this.input.jump && this.jumping.lastButtonDownTime < 0f && this.canControl) { this.jumping.lastButtonDownTime = single1; } if (!this._grounded) { acceleration.y = -this.movement.setup.gravity; acceleration.z = 0f; acceleration.x = 0f; if (this.jumping.jumping && this.jumping.holdingJumpButton && single1 < this.jumping.lastStartTime + this.jumping.setup.extraHeight / this.jumpVerticalSpeedCalculator.CalculateVerticalSpeed(ref this.jumping.setup, ref this.movement.setup)) { acceleration.x = acceleration.x + this.jumping.jumpDir.x * this.movement.setup.gravity; acceleration.y = acceleration.y + this.jumping.jumpDir.y * this.movement.setup.gravity; acceleration.z = acceleration.z + this.jumping.jumpDir.z * this.movement.setup.gravity; } vector3.x = acceleration.x * deltaTime; vector3.y = acceleration.y * deltaTime; vector3.z = acceleration.z * deltaTime; velocity.y = this.movement.velocity.y + vector3.y; if (this.movement.setup.inputAirVelocityRatio == 1f) { velocity.x = velocity.x + vector3.x; velocity.z = velocity.z + vector3.z; } else if (this.movement.setup.inputAirVelocityRatio != 0f) { float single2 = 1f - this.movement.setup.inputAirVelocityRatio; velocity.x = velocity.x * this.movement.setup.inputAirVelocityRatio + this.movement.velocity.x * single2 + vector3.x; velocity.z = velocity.z * this.movement.setup.inputAirVelocityRatio + this.movement.velocity.z * single2 + vector3.z; } else { velocity.x = this.movement.velocity.x + vector3.x; velocity.z = this.movement.velocity.z + vector3.z; } if (-velocity.y > this.movement.setup.maxFallSpeed) { velocity.y = -this.movement.setup.maxFallSpeed; } if (this.movement.setup.maxAirHorizontalSpeed > 0f) { float single3 = velocity.x * velocity.x + velocity.z * velocity.z; if (single3 > this.movement.setup.maxAirHorizontalSpeed * this.movement.setup.maxAirHorizontalSpeed) { float single4 = this.movement.setup.maxAirHorizontalSpeed / Mathf.Sqrt(single3); velocity.x = velocity.x * single4; velocity.z = velocity.z * single4; } } simulate = true; } else { if (velocity.y < 0f) { velocity.y = velocity.y - this.movement.setup.gravity * deltaTime; } else { velocity.y = -this.movement.setup.gravity * deltaTime; } if (!this.jumping.setup.enable || !this.canControl || single1 - this.jumping.lastButtonDownTime >= 0.2f || this.minTimeBetweenJumps > 0f && single1 - this.jumping.lastLandTime < this.minTimeBetweenJumps) { this.jumping.holdingJumpButton = false; } else if (this.minTimeBetweenJumps <= 0f || single1 - this.jumping.lastLandTime >= this.minTimeBetweenJumps) { this._grounded = false; this.jumping.jumping = true; this.jumping.lastStartTime = single1; this.jumping.lastButtonDownTime = -100f; this.jumping.holdingJumpButton = true; Vector3 vector31 = Vector3.up; Vector3 vector32 = this._groundNormal; single = (!this.tooSteep ? this.jumping.setup.perpAmount : this.jumping.setup.steepPerpAmount); this.jumping.jumpDir = Vector3.Slerp(vector31, vector32, single); float single5 = this.jumpVerticalSpeedCalculator.CalculateVerticalSpeed(ref this.jumping.setup, ref this.movement.setup); velocity.x = velocity.x + this.jumping.jumpDir.x * single5; velocity.y = this.jumping.jumpDir.y * single5; velocity.z = velocity.z + this.jumping.jumpDir.z * single5; if (this.movingPlatform.setup.enable && (this.movingPlatform.setup.movementTransfer == CCMotor.JumpMovementTransfer.InitTransfer || this.movingPlatform.setup.movementTransfer == CCMotor.JumpMovementTransfer.PermaTransfer)) { this.movement.frameVelocity = this.movingPlatform.platformVelocity; velocity.x = velocity.x + this.movingPlatform.platformVelocity.x; velocity.y = velocity.y + this.movingPlatform.platformVelocity.y; velocity.z = velocity.z + this.movingPlatform.platformVelocity.z; } this.jumping.startedJumping = true; if (this.sendJumpMessage) { this.RouteMessage("OnJump", SendMessageOptions.DontRequireReceiver); } } else if (this.sendJumpFailureMessage) { this.RouteMessage("OnJumpFailed", SendMessageOptions.DontRequireReceiver); } simulate = false; } }