player_hitbox.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using HQFPSWeapons;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. [RequireComponent(typeof(Collider))]
  6. public class player_hitbox : MonoBehaviour, IDamageable
  7. {
  8. public shotType hitboxType;
  9. netPlayer zombieScript;
  10. void Start()
  11. {
  12. zombieScript = GetComponentInParent<netPlayer>();
  13. }
  14. public LivingEntity GetEntity()
  15. {
  16. return null;
  17. }
  18. public void TakeDamage(HealthEventData damageData)
  19. {
  20. //transform.root.GetComponent<zombieV2>().
  21. if(zombieScript == null) { Debug.LogError("No playerScriptFound!"); return; } //incase if the zombie is dead already
  22. zombieScript.hitboxDamage(damageData,hitboxType);
  23. if (zombieScript.effectIdx == zombieScript.BloodFX.Length) zombieScript.effectIdx = 0;
  24. float angle = Mathf.Atan2(damageData.HitNormal.x, damageData.HitNormal.z) * Mathf.Rad2Deg + 180;
  25. var instance = Instantiate(zombieScript.BloodFX[zombieScript.effectIdx], damageData.HitPoint, Quaternion.Euler(0, angle + 90, 0));
  26. zombieScript.effectIdx++;
  27. var settings = instance.GetComponent<BFX_BloodSettings>();
  28. //settings.FreezeDecalDisappearance = InfiniteDecal;
  29. var attachBloodInstance = Instantiate(zombieScript.BloodAttach, transform);
  30. var bloodT = attachBloodInstance.transform;
  31. bloodT.position = damageData.HitPoint;
  32. bloodT.localRotation = Quaternion.identity;
  33. bloodT.localScale = Vector3.one * Random.Range(0.75f, 1.2f);
  34. bloodT.LookAt(damageData.HitPoint + damageData.HitNormal, damageData.HitDirection);
  35. bloodT.Rotate(90, 0, 0);
  36. Debug.Log(hitboxType.ToString());
  37. }
  38. public void OnCollisionEnter(Collision col)
  39. {
  40. Rigidbody rb = col.transform.GetComponentInParent<Rigidbody>();
  41. if (rb != null)
  42. {
  43. if (rb.tag == "Player")
  44. {
  45. Debug.Log($"{rb.name} Hit zombie {zombieScript.transform.name} with speed of {rb.velocity.magnitude}");
  46. if (col.transform.GetComponent<Rigidbody>().velocity.magnitude > 0)
  47. {
  48. if (zombieScript.effectIdx == zombieScript.BloodFX.Length) zombieScript.effectIdx = 0;
  49. float angle = Mathf.Atan2(col.impulse.normalized.x, col.impulse.normalized.z) * Mathf.Rad2Deg + 180;
  50. var instance = Instantiate(zombieScript.BloodFX[zombieScript.effectIdx], col.GetContact(0).point, Quaternion.Euler(0, angle + 90, 0));
  51. zombieScript.effectIdx++;
  52. var settings = instance.GetComponent<BFX_BloodSettings>();
  53. //settings.FreezeDecalDisappearance = InfiniteDecal;
  54. var attachBloodInstance = Instantiate(zombieScript.BloodAttach, transform);
  55. var bloodT = attachBloodInstance.transform;
  56. bloodT.position = col.GetContact(0).point;
  57. bloodT.localRotation = Quaternion.identity;
  58. bloodT.localScale = Vector3.one * Random.Range(0.75f, 1.2f);
  59. bloodT.LookAt(col.GetContact(0).point + col.GetContact(0).normal, col.impulse);
  60. bloodT.Rotate(90, 0, 0);
  61. Debug.Log(hitboxType.ToString());
  62. // GetComponent<Rigidbody>().AddForce(col.impulse*5);
  63. HealthEventData damageData = new HealthEventData(-col.impulse.magnitude, DamageType.Hit);
  64. TakeDamage(damageData);
  65. }
  66. }
  67. }
  68. else
  69. {
  70. // Debug.Log("Contact from " + col.transform.name + " with " + col.impulse);
  71. }
  72. }
  73. }