44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using UnityEngine;
|
|
|
|
using Colosseum.Player;
|
|
|
|
namespace Colosseum.Skills.Effects
|
|
{
|
|
/// <summary>
|
|
/// 넉백 효과
|
|
/// </summary>
|
|
[CreateAssetMenu(fileName = "KnockbackEffect", menuName = "Colosseum/Skills/Effects/Knockback")]
|
|
public class KnockbackEffect : SkillEffect
|
|
{
|
|
[Header("Knockback Settings")]
|
|
[Min(0f)] [SerializeField] private float force = 5f;
|
|
[SerializeField] private float upwardForce = 2f;
|
|
[Min(0.05f)] [SerializeField] private float duration = 0.2f;
|
|
|
|
protected override void ApplyEffect(GameObject caster, GameObject target)
|
|
{
|
|
if (target == null || caster == null) return;
|
|
|
|
Vector3 direction = target.transform.position - caster.transform.position;
|
|
direction.y = 0f;
|
|
if (direction.sqrMagnitude <= 0.0001f)
|
|
direction = caster.transform.forward;
|
|
else
|
|
direction.Normalize();
|
|
|
|
Vector3 knockbackVelocity = direction * force + Vector3.up * upwardForce;
|
|
|
|
if (target.TryGetComponent<HitReactionController>(out var hitReactionController))
|
|
{
|
|
hitReactionController.ApplyKnockback(knockbackVelocity, duration);
|
|
return;
|
|
}
|
|
|
|
if (target.TryGetComponent<PlayerMovement>(out var playerMovement))
|
|
{
|
|
playerMovement.ApplyForcedMovement(knockbackVelocity, duration);
|
|
}
|
|
}
|
|
}
|
|
}
|