// Update is called once per frame void Update() { if (hand.isBurned()) { rbody.MovePosition(rbody.transform.position + new Vector3(0, hand.getBurnRatio()) * Time.deltaTime * moveSpeed); rbody.MoveRotation(Mathf.Lerp(rbody.rotation, 2 * maxRot * Random.Range(-1.0f, 1.0f), 0.4f)); } else { float HorizontalAxis = MinigameInputHelper.GetHorizontalValue(hand.player); float VerticalAxis = MinigameInputHelper.GetVerticalValue(hand.player); rbody.MovePosition(rbody.transform.position + new Vector3(HorizontalAxis, VerticalAxis) * Time.deltaTime * moveSpeed); rbody.MoveRotation(Mathf.Lerp(rbody.rotation, maxRot * -HorizontalAxis, 0.1f)); } }
// Update is called once per frame void Update() { // For preview purposes, update current angle to the start angle in editor only if (!Application.isPlaying) { CurrentAngleDegrees = StartAngleDegrees; } // Set position based on Current Angle Vector2 OffsetVector = new Vector2(Mathf.Cos(Mathf.Deg2Rad * CurrentAngleDegrees), Mathf.Sin(Mathf.Deg2Rad * CurrentAngleDegrees)); transform.position = RotationCenter.position + (Vector3)OffsetVector * RadiusAwayFromCenter; //Set rotation based on Current Angle transform.rotation = Quaternion.Euler(0, 0, CurrentAngleDegrees); // Update the Current Angle to move to target direction Vector2 TargetVector = new Vector2(MinigameInputHelper.GetHorizontalValue(PlayerNum), MinigameInputHelper.GetVerticalValue(PlayerNum)).normalized; if (Mathf.Abs(TargetVector.x) > 0 || Mathf.Abs(TargetVector.y) > 0) { float TargetAngleDegrees = Mathf.Rad2Deg * Mathf.Atan2(TargetVector.y, TargetVector.x); float AngleDistance = Mathf.DeltaAngle(CurrentAngleDegrees, TargetAngleDegrees); float AngleDirection = Mathf.Sign(AngleDistance); if (Mathf.Abs(AngleDistance) < RotationSpeedDegreePerSecond) { CurrentAngleDegrees = TargetAngleDegrees; } else { CurrentAngleDegrees += RotationSpeedDegreePerSecond * AngleDirection; } } }