From 277c93d5e98bcdf28b63ab460d18ca2b05760f4b Mon Sep 17 00:00:00 2001 From: james7132 Date: Sat, 24 Feb 2018 23:55:54 -0800 Subject: [PATCH] Add utilty methods/functions for getting Directions --- Assets/DanmakU/Runtime/Core/Danmaku.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Assets/DanmakU/Runtime/Core/Danmaku.cs b/Assets/DanmakU/Runtime/Core/Danmaku.cs index add2662b..d215f170 100644 --- a/Assets/DanmakU/Runtime/Core/Danmaku.cs +++ b/Assets/DanmakU/Runtime/Core/Danmaku.cs @@ -65,6 +65,11 @@ public float Rotation { [MethodImpl(MethodImplOptions.AggressiveInlining)] set { Pool.Rotations[Id] = value; } } + /// + /// Gets the direction the Danmaku is facing. Guarenteed to be a unit vector. + /// + public Vector2 Direction => GetDirection(Pool.Rotations[Id]); + /// /// Gets or sets the speed of the Danmaku. /// @@ -154,6 +159,15 @@ public void ApplyState(DanmakuState state) { Color = state.Color; } + /// + /// Convert a Danmaku rotation into a unit vector. + /// + /// the rotation of the Danmaku. + /// the unit vector representing the way the bullet is facing. + 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; }