Browse Source

Merge branch 'develop' of https://git.joshuareason.com/Jam/GGJ_2021 into develop

develop
Mack Branagan 3 years ago
parent
commit
b8b5f3dd8c
1 changed files with 38 additions and 9 deletions
  1. +38
    -9
      Assets/Scripts/Behaviours/YeetController.cs

+ 38
- 9
Assets/Scripts/Behaviours/YeetController.cs View File

@ -6,18 +6,22 @@ public class YeetController : MonoBehaviour
{
public GameObject parent { get; set; }
public float yeetVelocity = 10f;
public float yeetVelocity = 5f;
public float yeetDuration = 2f;
public enum YeetState { Unheld, Held, Yeeting };
public YeetState yeetState { get; private set; } = YeetState.Unheld;
private GameObject _child;
private float _time;
private float m_time;
private GameObject m_child;
private GameObject m_body;
private float m_velocityWindup;
private LineRenderer m_lineRenderer;
private void Awake()
{
m_body = this.gameObject;
@ -28,39 +32,63 @@ public class YeetController : MonoBehaviour
_child = child;
_child.transform.parent = parent.transform;
yeetState = YeetState.Held;
m_lineRenderer = gameObject.AddComponent<LineRenderer>();
}
public void Yeet()
{
_child.transform.parent = null;
_child.transform.rotation = parent.transform.rotation;
_child.GetComponent<Rigidbody>().velocity = _child.transform.forward * yeetVelocity + _child.transform.up * yeetVelocity;
_child.GetComponent<Rigidbody>().velocity = _child.transform.forward * m_velocityWindup + _child.transform.up * m_velocityWindup;
yeetState = YeetState.Yeeting;
_time = yeetDuration;
m_time = yeetDuration;
m_velocityWindup = 0;
Destroy(m_lineRenderer);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
switch(yeetState)
{
case YeetState.Yeeting:
//_child.transform.position += _child.transform.forward * yeetVelocity * Time.deltaTime;
_time -= Time.deltaTime;
m_time -= Time.deltaTime;
if(_time <= 0f)
if(m_time <= 0f)
{
Debug.Log("YeetController.Update: Yeet finished");
yeetState = YeetState.Unheld;
}
break;
case YeetState.Held:
// draw yeet lines
if(m_velocityWindup < yeetVelocity)
{
m_velocityWindup += 0.01f;
}
Vector3 velocity = parent.transform.forward * m_velocityWindup + parent.transform.up * m_velocityWindup;
float t;
t = (-1f * velocity.y) / Physics.gravity.y;
t = 2f * t;
m_lineRenderer.positionCount = 10;
Vector3 trajectoryPoint;
for (int i = 0; i < m_lineRenderer.positionCount; i++)
{
float time = t * i / (float)(m_lineRenderer.positionCount);
trajectoryPoint = parent.transform.position + velocity * time + 0.5f * Physics.gravity * time * time;
m_lineRenderer.SetPosition(i, trajectoryPoint);
}
break;
case YeetState.Unheld:
_child = null;
@ -98,4 +126,5 @@ public class YeetController : MonoBehaviour
break;
}
}
}

Loading…
Cancel
Save