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.

54 lines
1.3 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. public float speed;
  11. private float timer = 0;
  12. public float minRandTimer;
  13. public float maxRandTimer;
  14. public float randTimer;
  15. void Start()
  16. {
  17. rb = GetComponent<Rigidbody>();
  18. currentVector = RandomNormVector();
  19. targetVector = RandomNormVector();
  20. randTimer = Random.Range(minRandTimer, maxRandTimer);
  21. }
  22. void FixedUpdate()
  23. {
  24. currentVector = Vector3.Slerp(currentVector, targetVector, Time.deltaTime);
  25. rb.MovePosition(transform.position + (currentVector * speed));
  26. timer += Time.deltaTime;
  27. if (timer > randTimer)
  28. {
  29. targetVector = RandomNormVector();
  30. timer = 0;
  31. randTimer = Random.Range(minRandTimer, maxRandTimer);
  32. }
  33. }
  34. public Vector3 RandomNormVector()
  35. {
  36. float _x = Random.Range(-1f, 1f);
  37. float _z = Random.Range(-1f, 1f);
  38. return new Vector3(_x, 0, _z).normalized;
  39. }
  40. private void OnDrawGizmos()
  41. {
  42. Gizmos.DrawLine(transform.position, transform.position + currentVector);
  43. }
  44. }