|
@ -13,11 +13,15 @@ public class BoatRowController : MonoBehaviour |
|
|
|
|
|
|
|
|
#region Inspector Fields
|
|
|
#region Inspector Fields
|
|
|
public Transform m_oarTip; |
|
|
public Transform m_oarTip; |
|
|
public UnityEvent m_OnRow; |
|
|
|
|
|
|
|
|
public UnityEvent<float> m_OnRow; |
|
|
|
|
|
public UnityEvent m_OnBrake; |
|
|
|
|
|
public int velocityOverFrames = 8; |
|
|
#endregion Inspector Fields
|
|
|
#endregion Inspector Fields
|
|
|
|
|
|
|
|
|
#region Private Fields
|
|
|
#region Private Fields
|
|
|
private Vector3 m_lastKnownOarPosition; |
|
|
private Vector3 m_lastKnownOarPosition; |
|
|
|
|
|
|
|
|
|
|
|
private Queue<float> m_velocityQueue = new Queue<float>(); |
|
|
#endregion Private Fields
|
|
|
#endregion Private Fields
|
|
|
|
|
|
|
|
|
#region Getters
|
|
|
#region Getters
|
|
@ -60,7 +64,8 @@ public class BoatRowController : MonoBehaviour |
|
|
OarController oar = other.GetComponentInParent<OarController>(); |
|
|
OarController oar = other.GetComponentInParent<OarController>(); |
|
|
if (oar != null) |
|
|
if (oar != null) |
|
|
{ |
|
|
{ |
|
|
m_lastKnownOarPosition = m_oarTip.localPosition; |
|
|
|
|
|
|
|
|
m_lastKnownOarPosition = transform.InverseTransformPoint(m_oarTip.position); |
|
|
|
|
|
m_velocityQueue = new Queue<float>(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -69,20 +74,50 @@ public class BoatRowController : MonoBehaviour |
|
|
OarController oar = other.GetComponentInParent<OarController>(); |
|
|
OarController oar = other.GetComponentInParent<OarController>(); |
|
|
if(oar != null) |
|
|
if(oar != null) |
|
|
{ |
|
|
{ |
|
|
Vector3 direction = m_lastKnownOarPosition - m_oarTip.localPosition; |
|
|
|
|
|
|
|
|
Vector3 localOarTipPosition = transform.InverseTransformPoint(m_oarTip.position); |
|
|
|
|
|
|
|
|
|
|
|
Vector3 direction = m_lastKnownOarPosition - localOarTipPosition; |
|
|
|
|
|
|
|
|
float directionality = Vector3.Dot(direction,Vector3.forward); |
|
|
float directionality = Vector3.Dot(direction,Vector3.forward); |
|
|
|
|
|
|
|
|
if (directionality > 0) |
|
|
|
|
|
|
|
|
m_velocityQueue.Enqueue(directionality * Time.deltaTime); |
|
|
|
|
|
|
|
|
|
|
|
if(m_velocityQueue.Count > velocityOverFrames) |
|
|
|
|
|
{ |
|
|
|
|
|
m_velocityQueue.Dequeue(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float averageVelocity = 0; |
|
|
|
|
|
if (m_velocityQueue.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
var v_arr = m_velocityQueue.ToArray(); |
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < v_arr.Length; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
averageVelocity += v_arr[i]; |
|
|
|
|
|
} |
|
|
|
|
|
averageVelocity /= v_arr.Length; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (averageVelocity > 0) |
|
|
{ |
|
|
{ |
|
|
Debug.Log($"Row! ({directionality})"); |
|
|
|
|
|
m_OnRow.Invoke(); |
|
|
|
|
|
|
|
|
if(averageVelocity < 0.000001) |
|
|
|
|
|
{ |
|
|
|
|
|
m_OnBrake.Invoke(); |
|
|
|
|
|
Debug.Log($"Brake! ({averageVelocity})"); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log($"Row! ({averageVelocity})"); |
|
|
|
|
|
m_OnRow.Invoke(averageVelocity); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
Debug.Log($"No Row: {directionality}"); |
|
|
|
|
|
|
|
|
Debug.Log($"No Row: {averageVelocity}"); |
|
|
|
|
|
m_OnBrake.Invoke(); |
|
|
} |
|
|
} |
|
|
m_lastKnownOarPosition=m_oarTip.localPosition; |
|
|
|
|
|
|
|
|
m_lastKnownOarPosition = localOarTipPosition; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|