Skip to content

Commit

Permalink
Add utilty methods/functions for getting Directions
Browse files Browse the repository at this point in the history
  • Loading branch information
james7132 committed Feb 25, 2018
1 parent 7a9a3b3 commit 277c93d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Assets/DanmakU/Runtime/Core/Danmaku.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public float Rotation {
[MethodImpl(MethodImplOptions.AggressiveInlining)] set { Pool.Rotations[Id] = value; }
}

/// <summary>
/// Gets the direction the Danmaku is facing. Guarenteed to be a unit vector.
/// </summary>
public Vector2 Direction => GetDirection(Pool.Rotations[Id]);

/// <summary>
/// Gets or sets the speed of the Danmaku.
/// </summary>
Expand Down Expand Up @@ -154,6 +159,15 @@ public void ApplyState(DanmakuState state) {
Color = state.Color;
}

/// <summary>
/// Convert a Danmaku rotation into a unit vector.
/// </summary>
/// <param name="rotation">the rotation of the Danmaku.</param>
/// <returns>the unit vector representing the way the bullet is facing.</returns>
public static Vector2 GetDirection(float rotation) {
return new Vector2(Mathf.Cos(rotation), Mathf.Sin(rotation));
}

public static bool operator ==(Danmaku lhs, Danmaku rhs) {
return lhs.Id == rhs.Id && lhs.Pool == rhs.Pool;
}
Expand Down

0 comments on commit 277c93d

Please sign in to comment.