Assignment for RMIT Mixed Reality in 2020
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.

58 lines
1.4 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ArrowBehaviour : MonoBehaviour
  5. {
  6. [SerializeField]
  7. private float m_rotationSpeed = 1f;
  8. [SerializeField]
  9. private Transform m_tip;
  10. [SerializeField]
  11. private float m_lifeTime = 45;
  12. private Rigidbody m_rb;
  13. ContactPoint[] contactPoints;
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. m_rb = GetComponent<Rigidbody>();
  18. Destroy(gameObject, m_lifeTime);
  19. }
  20. // Update is called once per frame
  21. void FixedUpdate()
  22. {
  23. if (m_rb != null && !m_rb.isKinematic)
  24. transform.forward = Vector3.Slerp(transform.forward, m_rb.velocity, m_rotationSpeed);
  25. }
  26. private void OnCollisionEnter(Collision collision)
  27. {
  28. contactPoints = new ContactPoint[collision.contactCount];
  29. collision.GetContacts(contactPoints);
  30. foreach (ContactPoint point in contactPoints)
  31. {
  32. //Debug.Log($"point: {point.point}, position: {m_tip.position}. [{Vector3.Distance(point.point, m_tip.position)}]");
  33. if (Vector3.Distance(point.point, m_tip.position) < 0.1f)
  34. {
  35. Destroy(GetComponent<ArtificialGravity>());
  36. Destroy(m_rb);
  37. //m_rb.isKinematic = true;
  38. transform.parent = point.otherCollider.transform;
  39. return;
  40. }
  41. }
  42. }
  43. }