Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Unity.VisualScripting;
  4. using UnityEngine;
  5.  
  6. [CreateAssetMenu(fileName = "New Melee Ability", menuName = "Ability System/Melee Ability")]
  7. public class MeleeAttackAbility : Ability
  8. {
  9. public float attackRange = 2f;
  10. public float attackRadius = 0.5f;
  11. public LayerMask groundLayer;
  12.  
  13. public override void Activate(GameObject parent)
  14. {
  15. TurnToMousePosition(parent.transform, groundLayer);
  16. parent.GetComponent<PlayerMovement>().StopMovement();
  17.  
  18.  
  19. Vector3 startPoint = parent.transform.position;
  20. Vector3 endPoint = startPoint + parent.transform.forward * attackRange;
  21.  
  22. Collider[] hitColliders = Physics.OverlapCapsule(startPoint, endPoint, attackRadius, hitMask.value);
  23.  
  24. foreach (var hitCollider in hitColliders)
  25. {
  26. Debug.Log(hitCollider.gameObject.name);
  27. }
  28.  
  29. DebugExtension.DebugCapsule(startPoint, endPoint, Color.red, attackRadius, 1f);
  30. }
  31.  
  32. void TurnToMousePosition(Transform parent, LayerMask groundLayer)
  33. {
  34. // Create a ray from the camera through the mouse position
  35. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  36. RaycastHit hit;
  37.  
  38.  
  39. if (Physics.Raycast(ray, out hit, Mathf.Infinity, groundLayer))
  40. {
  41. Vector3 mouseWorldPosition = hit.point;
  42. DebugExtension.DebugWireSphere(mouseWorldPosition, Color.red, 0.3f, 1f);
  43. Vector3 lookAtPosition = new Vector3(mouseWorldPosition.x, parent.position.y, mouseWorldPosition.z);
  44. parent.LookAt(lookAtPosition);
  45. Debug.Log($"Current Rotation: {parent.rotation.eulerAngles}");
  46. }
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement