Global Game Jam 2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class BabyController : MonoBehaviour
  5. {
  6. private Vector3 currentVector;
  7. [HideInInspector]
  8. public Vector3 targetVector;
  9. private Rigidbody rb;
  10. private YeetHandle yeetHandle;
  11. public float speed;
  12. private float timer = 0;
  13. public float minRandTimer;
  14. public float maxRandTimer;
  15. public float randTimer;
  16. void Start()
  17. {
  18. rb = GetComponent<Rigidbody>();
  19. yeetHandle = GetComponent<YeetHandle>();
  20. currentVector = RandomNormVector();
  21. targetVector = RandomNormVector();
  22. randTimer = Random.Range(minRandTimer, maxRandTimer);
  23. }
  24. void FixedUpdate()
  25. {
  26. if(!yeetHandle.held)
  27. {
  28. currentVector = Vector3.Slerp(currentVector, targetVector, Time.deltaTime);
  29. rb.MovePosition(transform.position + (currentVector * speed));
  30. }
  31. timer += Time.deltaTime;
  32. if (timer > randTimer)
  33. {
  34. targetVector = RandomNormVector();
  35. timer = 0;
  36. randTimer = Random.Range(minRandTimer, maxRandTimer);
  37. }
  38. }
  39. public Vector3 RandomNormVector()
  40. {
  41. float _x = Random.Range(-1f, 1f);
  42. float _z = Random.Range(-1f, 1f);
  43. return new Vector3(_x, 0, _z).normalized;
  44. }
  45. private void OnDrawGizmos()
  46. {
  47. Gizmos.DrawLine(transform.position, transform.position + currentVector);
  48. }
  49. }