|
|
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class ArrowBehaviour : MonoBehaviour
- {
-
- [SerializeField]
- private float m_rotationSpeed = 1f;
-
- [SerializeField]
- private Transform m_tip;
-
- [SerializeField]
- private float m_lifeTime = 45;
-
- private Rigidbody m_rb;
-
-
- ContactPoint[] contactPoints;
-
- // Start is called before the first frame update
- void Start()
- {
- m_rb = GetComponent<Rigidbody>();
- Destroy(gameObject, m_lifeTime);
- }
-
- // Update is called once per frame
- void FixedUpdate()
- {
- if (m_rb != null && !m_rb.isKinematic)
- transform.forward = Vector3.Slerp(transform.forward, m_rb.velocity, m_rotationSpeed);
- }
-
-
- private void OnCollisionEnter(Collision collision)
- {
-
- contactPoints = new ContactPoint[collision.contactCount];
- collision.GetContacts(contactPoints);
-
- foreach (ContactPoint point in contactPoints)
- {
- //Debug.Log($"point: {point.point}, position: {m_tip.position}. [{Vector3.Distance(point.point, m_tip.position)}]");
- if (Vector3.Distance(point.point, m_tip.position) < 0.1f)
- {
- Destroy(GetComponent<ArtificialGravity>());
- Destroy(m_rb);
- //m_rb.isKinematic = true;
- transform.parent = point.otherCollider.transform;
- return;
- }
-
-
- }
- }
- }
|