Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1.  
  2. public void CastLightning()
  3. {
  4. GameObject ligtning = Instantiate(lightningPrefab, Vector3.zero, Quaternion.identity);
  5. LightningBoltScript lightningScript = ligtning.GetComponent<LightningBoltScript>();
  6.  
  7. lightningScript.StartPosition = shootPoint.position;
  8.  
  9. if (hit.collider != null)
  10. {
  11. lightningScript.EndPosition = hit.point;
  12. if (hit.collider.gameObject.CompareTag("Player"))
  13. {
  14. hit.collider.gameObject.GetComponent<PlayerHealth>().TakeDamage(85); //TEMP
  15. }
  16. }
  17. else
  18. {
  19. lightningScript.EndPosition = transform.forward * 100;
  20. }
  21.  
  22. lineR.enabled = false;
  23. lerpPercent = 0;
  24. }
  25.  
  26. public void InitiateAiming() //для типов врагов, которые целятся, вызывается в начале анимации
  27. {
  28. lineR.enabled = true;
  29. timer = Time.time + aimTime; //заново целимся
  30. }
  31. private void Aim()
  32. {
  33. lineR.SetPosition(0, shootPoint.position);
  34.  
  35. if (Time.time < timer)
  36. {
  37. targetRotation = Quaternion.LookRotation(playerTr.position - thisTr.position);
  38. lerpPercent += 0.1f * Time.fixedDeltaTime;
  39. thisTr.rotation = Quaternion.Lerp(thisTr.rotation, targetRotation, lerpPercent);
  40. Vector3 normal = GetPointOfContactNormal(thisTr.position + Vector3.up, new Vector3(thisTr.forward.x, (playerTr.position - thisTr.position).normalized.y, thisTr.forward.z));
  41. lineR.SetPosition(1, hit.point);
  42. }
  43. else if(lineR.enabled)
  44. {
  45. Vector3 normal = GetPointOfContactNormal(thisTr.position + Vector3.up, new Vector3(thisTr.forward.x, (playerTr.position - thisTr.position).normalized.y, thisTr.forward.z));
  46. if(normal != Vector3.zero)
  47. lineR.SetPosition(1, hit.point);
  48. else
  49. lineR.SetPosition(1, thisTr.forward * 100);
  50. }
  51.  
  52. }
  53. private Vector3 GetPointOfContactNormal(Vector3 pos, Vector3 dir)
  54. {
  55. Ray ray = new Ray(pos, dir);
  56. if (Physics.Raycast(ray.origin, ray.direction, out hit, 300, obstaclesAndPlayerLayerMask))
  57. {
  58. return hit.normal;
  59. }
  60.  
  61. return Vector3.zero;
  62. }
  63.  
  64. public void TurnOffLinecast()
  65. {
  66. lineR.enabled = false;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement