Skip to content

Commit

Permalink
Make beat line shaking animation horizontal.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpx committed Apr 22, 2018
1 parent 771c260 commit c380bf7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Assets/Scripts/BeatLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class BeatLine : MonoBehaviour
private AudioSource _audioSource;
private DifficultyManager _difficultyManager;

private Vector3 _localPosition;

public void Run(float timeOffset, AudioSource audioSource)
{
_running = true;
Expand All @@ -56,6 +58,8 @@ void Start()
_lineEnd = positions[positions.Length - 1].x;
_lineLength = _lineEnd - _lineStart;

_localPosition = transform.localPosition;

_difficultyManager = GetComponentInParent<DifficultyManager>();

SpawnCursor();
Expand Down Expand Up @@ -123,29 +127,29 @@ void shakeRight(Vector3 p0, int count)
return;
}

var magnitude = 0.25f;
var magnitude = 0.1f;
var p1 = transform.localPosition;
var p2 = p0 + new Vector3(magnitude, 0f, 0f);
var p2 = p0 + new Vector3(0f, 0f, magnitude);

gameObject.Tween("ShakeBar", p1, p2, 0.01f, TweenScaleFunctions.CubicEaseIn, t => {
gameObject.Tween("ShakeBar", p1, p2, 0.04f, TweenScaleFunctions.CubicEaseIn, t => {
transform.position = t.CurrentValue;
}, t1 => shakeLeft(p0, count));
}

void shakeLeft(Vector3 p0, int count)
{
var magnitude = 0.25f;
var magnitude = 0.1f;
var p1 = transform.localPosition;
var p2 = p0 - new Vector3(magnitude, 0f, 0f);
var p2 = p0 - new Vector3(0f, 0f, magnitude);

gameObject.Tween("ShakeBar", p1, p2, 0.01f, TweenScaleFunctions.CubicEaseIn, t => {
gameObject.Tween("ShakeBar", p1, p2, 0.04f, TweenScaleFunctions.CubicEaseIn, t => {
transform.position = t.CurrentValue;
}, t1 => shakeRight(p0, count));
}

void OnMiss()
{
shakeRight(transform.localPosition, 5);
shakeRight(_localPosition, 4);

Debug.Log("OnMiss");
onMiss.Invoke();
Expand Down

0 comments on commit c380bf7

Please sign in to comment.