Commit 7a796ddb authored by Unknown's avatar Unknown
Browse files

Bug Fix PlayerAnimation

parent c7d071b3
......@@ -8,14 +8,20 @@ using _Game.Scripts.Scriptable_Object;
public class PlayerAnimation : MonoBehaviour
{
[Header("Scaling")] public AnimationCurve m_AirScale;
public bool m_ScalingActive = true;
public float m_Time = 10f;
public float m_SizePerCharge = 0.2f;
private Vector3 m_OriginScale;
private int m_PreviousAirCharges = 0;
private int m_CurrentAirCharges = 0;
[Header("Rotation")] public float m_Speed = 3f;
public bool m_RotationActive = false;
public float m_Radius = 1f;
public float m_RadiusSinDifference = 0.3f;
public float m_MaxScale = 0.3f;
public GameObject m_ElementPrefab;
public Transform m_ElementOrbParent;
public Transform m_RotationOrigin;
public Vector2 m_RotationOriginOffset;
public Sprite m_AirSprite;
......@@ -36,11 +42,7 @@ public class PlayerAnimation : MonoBehaviour
private bool m_isAnimating = false;
private bool m_isScaled = false;
private bool m_isRotating = false;
private int m_PreviousCharges = 0;
private Vector3 m_OriginSize;
private Vector2 m_OriginOffset;
private float m_OriginCheckDistance;
// Start is called before the first frame update
......@@ -49,9 +51,7 @@ public class PlayerAnimation : MonoBehaviour
r_Controller = GetComponent<MovementController>();
r_Collider2D = GetComponent<CapsuleCollider2D>();
m_OriginSize = transform.localScale;
m_OriginOffset = r_Controller.GroundCheckOffset;
m_OriginCheckDistance = r_Controller.GroundCheckDistance;
m_OriginScale = transform.localScale;
m_ElementOrbTransforms = new List<GameObject>();
m_ElementOrbRenderer = new List<SpriteRenderer>();
......@@ -75,48 +75,71 @@ public class PlayerAnimation : MonoBehaviour
switch (r_State.GetCurrentElement())
{
case InfusedElement.None:
m_isRotating = false;
SetRotationOrbsActive(false, 5);
ScalePlayer();
break;
case InfusedElement.Air:
ScalePlayer();
SetRotationOrbsActive(true, r_State.GetCharges());
SetRotationOrbSprite(m_AirSprite);
if (!m_isRotating)
if (m_ScalingActive) ScalePlayer();
if (m_RotationActive)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
m_isRotating = false;
SetRotationOrbsActive(false, 5);
}
break;
case InfusedElement.Air:
m_CurrentAirCharges = r_State.GetCharges();
if (m_ScalingActive) ScalePlayer();
/*if(m_isRotating) {
SetRotationOrbsActive(true, r_State.GetCharges());
SetRotationOrbSprite(m_AirSprite);
if (!m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
}
}*/
break;
case InfusedElement.Fire:
SetRotationOrbsActive(true, r_State.GetCharges());
SetRotationOrbSprite(m_FireSprite);
if (!m_isRotating)
if(m_ScalingActive)transform.localScale = m_OriginScale;
if (m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
SetRotationOrbsActive(true, r_State.GetCharges());
SetRotationOrbSprite(m_FireSprite);
if (!m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
}
}
break;
case InfusedElement.Earth:
SetRotationOrbsActive(true, r_State.GetCharges());
SetRotationOrbSprite(m_EarthSprite);
if (!m_isRotating)
if(m_ScalingActive)transform.localScale = m_OriginScale;
if (m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
SetRotationOrbsActive(true, r_State.GetCharges());
SetRotationOrbSprite(m_EarthSprite);
if (!m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
}
}
break;
case InfusedElement.Water:
SetRotationOrbsActive(true, r_State.GetCharges());
SetRotationOrbSprite(m_WaterSprite);
if (!m_isRotating)
if(m_ScalingActive)transform.localScale = m_OriginScale;
if (m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
SetRotationOrbsActive(true, r_State.GetCharges());
SetRotationOrbSprite(m_WaterSprite);
if (!m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
}
}
break;
......@@ -126,24 +149,24 @@ public class PlayerAnimation : MonoBehaviour
public void ScalePlayer()
{
int currentCharges = r_State.GetCharges();
int diff = currentCharges - m_PreviousCharges;
int diff = currentCharges - m_PreviousAirCharges;
//Debug.Log("current: " + currentCharges + " previous: " + m_PreviousCharges + " difference: " + diff);
if (!m_isAnimating || m_isAnimating)
{
if (diff > 0)
{
StartCoroutine(ScaleUp(diff));
StartCoroutine(ScaleUp(m_PreviousAirCharges, currentCharges));
}
else
{
StartCoroutine(ScaleDown(diff));
StartCoroutine(ScaleDown(m_PreviousAirCharges, currentCharges));
}
}
m_PreviousCharges = currentCharges;
m_PreviousAirCharges = currentCharges;
}
private IEnumerator ScaleUp(int amount)
private IEnumerator ScaleUp(int from, int to)
{
m_isAnimating = true;
m_isScaled = true;
......@@ -151,20 +174,21 @@ public class PlayerAnimation : MonoBehaviour
float step = 1 / m_Time;
float timer = 0.0f;
float x = 0f;
float diff = to - from;
while (timer <= m_Time)
{
x = m_SizePerCharge * Mathf.Abs(amount);
transform.localScale = Vector3.LerpUnclamped(s, s + new Vector3(x * Mathf.Sign(s.x), x, x),
x = m_SizePerCharge * Mathf.Abs(diff);
transform.localScale = Vector3.LerpUnclamped(s, s + new Vector3(x * Mathf.Sign(transform.localScale.x), x, x),
m_AirScale.Evaluate(timer / m_Time));
timer += Time.deltaTime;
yield return null;
}
transform.localScale = s + new Vector3(x * Mathf.Sign(s.x), x, x);
transform.localScale = s + new Vector3(x * Mathf.Sign(transform.localScale.x), x, x);
m_isAnimating = false;
}
private IEnumerator ScaleDown(int amount)
private IEnumerator ScaleDown(int from, int to)
{
m_isAnimating = true;
m_isScaled = false;
......@@ -172,10 +196,11 @@ public class PlayerAnimation : MonoBehaviour
float step = 1 / m_Time;
float timer = 0.0f;
float x = 0;
float diff = to - from;
while (timer <= m_Time)
{
x = m_SizePerCharge * Mathf.Abs(amount);
transform.localScale = Vector3.LerpUnclamped(s, s - new Vector3(x * Mathf.Sign(s.x), x, x),
x = m_SizePerCharge * Mathf.Abs(diff);
transform.localScale = Vector3.LerpUnclamped(s, s - new Vector3(x * Mathf.Sign(transform.localScale.x), x, x),
m_AirScale.Evaluate(timer / m_Time));
timer += Time.deltaTime;
yield return null;
......@@ -183,11 +208,11 @@ public class PlayerAnimation : MonoBehaviour
if (r_State.GetCharges() > 0)
{
transform.localScale = s - new Vector3(x * Mathf.Sign(s.x), x, x);
transform.localScale = s - new Vector3(x * Mathf.Sign(transform.localScale.x), x, x);
}
else
{
transform.localScale = m_OriginSize;
transform.localScale = m_OriginScale;
}
m_isAnimating = false;
......@@ -202,15 +227,16 @@ public class PlayerAnimation : MonoBehaviour
for (int i = 0; i < m_ElementOrbTransforms.Count; i++)
{
pos = m_TimeCounter;
if(r_State.GetCharges() > 0)
pos = m_TimeCounter + i * Mathf.Deg2Rad * (360 / r_State.GetCharges());
if (r_State.GetCharges() > 0)
pos = m_TimeCounter + i * Mathf.Deg2Rad * (360 / r_State.GetCharges());
float r = (m_Radius - m_RadiusSinDifference) + (m_RadiusSinDifference * Mathf.Sin(m_TimeCounter));
float x = Mathf.Cos(pos) * r;
float y = Mathf.Sin(pos) * r;
Vector3 offset = m_RotationOriginOffset;
//Transform elem = m_ElementOrbTransforms[i].transform;
m_ElementOrbTransforms[i].transform.position = m_RotationOrigin.position + offset + new Vector3(x, y, 0f);
m_ElementOrbTransforms[i].transform.position =
m_RotationOrigin.position + offset + new Vector3(x, y, 0f);
yield return new WaitForFixedUpdate();
}
}
......@@ -236,7 +262,6 @@ public class PlayerAnimation : MonoBehaviour
for (int i = 0; i < m_ElementOrbRenderer.Count; i++)
{
m_ElementOrbRenderer[i].sprite = s;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment