void FixedUpdate() { wind = DemoWind.getWind(transform.position.x); float zRotation = Mathf.Clamp(wind * horizontalIntensity, -maximumRotation, maximumRotation); float currentSpeed = bendSpeed; while (entities.Count > 0 && entities[0] == null) { entities.RemoveAt(0); insideCount--; } if (canBeBent && insideCount > 0) //Adding Entity Bending: { float xOffset = transform.position.x - entities[0].position.x; currentSpeed *= 2f; if (lastOffset == 0) { lastOffset = xOffset; } else if (lastOffset > 0 == xOffset > 0) { lastOffset = xOffset; } float factor = Mathf.Clamp01(1 - Mathf.Abs(lastOffset) * distanceFactor); if (lastOffset > 0) { zRotation += -entityRotation * factor; } else { zRotation += entityRotation * factor; } currentPushDown += (factor * entityPressDown - currentPushDown) * Time.fixedDeltaTime * currentSpeed; zRotation = Mathf.Clamp(zRotation, -maximumRotation, maximumRotation); } else { lastOffset = 0; currentPushDown -= currentPushDown * Time.fixedDeltaTime * currentSpeed * 1.5f; } currentAngle += (zRotation - currentAngle) * Time.fixedDeltaTime * currentSpeed; mat.SetFloat("_Rotation", currentAngle); mat.SetFloat("_Press_Down", currentPushDown); }
void Start() { c = this; }