private void UpdateLocal(ISkeletonAnimation animated) { Transform thisTransform = transform; Vector2 thisTransformPosition = thisTransform.position; float centerOfGravityX = thisTransformPosition.x + centerOfGravityXOffset; nearFoot.UpdateDistance(centerOfGravityX); farFoot.UpdateDistance(centerOfGravityX); balance = nearFoot.displacementFromCenter + farFoot.displacementFromCenter; distanceBetweenFeet = Mathf.Abs(nearFoot.worldPos.x - farFoot.worldPos.x); // Detect time to make a new step bool isTooOffBalance = Mathf.Abs(balance) > offBalanceThreshold; bool isFeetTooFarApart = distanceBetweenFeet > feetTooFarApartThreshold; bool timeForNewStep = isFeetTooFarApart || isTooOffBalance; if (timeForNewStep) { // Choose which foot to use for next step. Foot stepFoot, otherFoot; bool stepLegIsNearLeg = nearFoot.distanceFromCenter > farFoot.distanceFromCenter; if (stepLegIsNearLeg) { stepFoot = nearFoot; otherFoot = farFoot; } else { stepFoot = farFoot; otherFoot = nearFoot; } // Start a new step. if (!stepFoot.IsStepInProgress && otherFoot.IsPrettyMuchDoneStepping) { float newDisplacement = Foot.GetNewDisplacement(otherFoot.displacementFromCenter, comfyDistance, minimumSpaceBetweenFeet, maxNewStepDisplacement, forward, backward); stepFoot.StartNewStep(newDisplacement, centerOfGravityX, thisTransformPosition.y, footRayRaise, hits, footSize); } } float deltaTime = Time.deltaTime; float stepSpeed = baseLerpSpeed; stepSpeed += (Mathf.Abs(balance) - 0.6f) * 2.5f; // Animate steps that are in progress. nearFoot.UpdateStepProgress(deltaTime, stepSpeed, shuffleDistance, forward, backward); farFoot.UpdateStepProgress(deltaTime, stepSpeed, shuffleDistance, forward, backward); nearFootBone.SetLocalPosition(thisTransform.InverseTransformPoint(nearFoot.worldPos)); farFootBone.SetLocalPosition(thisTransform.InverseTransformPoint(farFoot.worldPos)); }
private void UpdateLocal(ISkeletonAnimation animated) { Transform transform = base.transform; Vector2 position = transform.position; float centerOfGravityX = position.x + this.centerOfGravityXOffset; this.nearFoot.UpdateDistance(centerOfGravityX); this.farFoot.UpdateDistance(centerOfGravityX); this.balance = this.nearFoot.displacementFromCenter + this.farFoot.displacementFromCenter; this.distanceBetweenFeet = Mathf.Abs((float)(this.nearFoot.worldPos.x - this.farFoot.worldPos.x)); bool flag = Mathf.Abs(this.balance) > this.offBalanceThreshold; if ((this.distanceBetweenFeet > this.feetTooFarApartThreshold) || flag) { Foot nearFoot; Foot farFoot; if (this.nearFoot.distanceFromCenter > this.farFoot.distanceFromCenter) { nearFoot = this.nearFoot; farFoot = this.farFoot; } else { nearFoot = this.farFoot; farFoot = this.nearFoot; } if (!nearFoot.IsStepInProgress && farFoot.IsPrettyMuchDoneStepping) { float newDistance = Foot.GetNewDisplacement(farFoot.displacementFromCenter, this.comfyDistance, this.minimumSpaceBetweenFeet, this.maxNewStepDisplacement, this.forward, this.backward); nearFoot.StartNewStep(newDistance, centerOfGravityX, position.y, this.footRayRaise, this.hits, this.footSize); } } float deltaTime = Time.deltaTime; float stepSpeed = this.baseLerpSpeed + ((Mathf.Abs(this.balance) - 0.6f) * 2.5f); this.nearFoot.UpdateStepProgress(deltaTime, stepSpeed, this.shuffleDistance, this.forward, this.backward); this.farFoot.UpdateStepProgress(deltaTime, stepSpeed, this.shuffleDistance, this.forward, this.backward); this.nearFootBone.SetPosition(transform.InverseTransformPoint((Vector3)this.nearFoot.worldPos)); this.farFootBone.SetPosition(transform.InverseTransformPoint((Vector3)this.farFoot.worldPos)); }