Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using Unity.VisualScripting;
- using UnityEngine;
- [CreateAssetMenu(fileName = "New Melee Ability", menuName = "Ability System/Melee Ability")]
- public class MeleeAttackAbility : Ability
- {
- public float attackRange = 2f;
- public float attackRadius = 0.5f;
- public LayerMask groundLayer;
- public override void Activate(GameObject parent)
- {
- TurnToMousePosition(parent.transform, groundLayer);
- parent.GetComponent<PlayerMovement>().StopMovement();
- Vector3 startPoint = parent.transform.position;
- Vector3 endPoint = startPoint + parent.transform.forward * attackRange;
- Collider[] hitColliders = Physics.OverlapCapsule(startPoint, endPoint, attackRadius, hitMask.value);
- foreach (var hitCollider in hitColliders)
- {
- Debug.Log(hitCollider.gameObject.name);
- }
- DebugExtension.DebugCapsule(startPoint, endPoint, Color.red, attackRadius, 1f);
- }
- void TurnToMousePosition(Transform parent, LayerMask groundLayer)
- {
- // Create a ray from the camera through the mouse position
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, Mathf.Infinity, groundLayer))
- {
- Vector3 mouseWorldPosition = hit.point;
- DebugExtension.DebugWireSphere(mouseWorldPosition, Color.red, 0.3f, 1f);
- Vector3 lookAtPosition = new Vector3(mouseWorldPosition.x, parent.position.y, mouseWorldPosition.z);
- parent.LookAt(lookAtPosition);
- Debug.Log($"Current Rotation: {parent.rotation.eulerAngles}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement