magic powers refactor WIP
This commit is contained in:
46
Assets/Scripts/Characters/Skills/ProjectileSpell.cs
Normal file
46
Assets/Scripts/Characters/Skills/ProjectileSpell.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Invector;
|
||||
|
||||
namespace Beyond
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Magic/Spells/Projectile Spell")]
|
||||
public class ProjectileSpell : SpellDefinition
|
||||
{
|
||||
[Header("Projectile Settings")]
|
||||
public GameObject projectilePrefab;
|
||||
public float spawnDelay = 0.2f; // Sync with animation hand throw
|
||||
public float lifeTime = 5f;
|
||||
public float aimHeightOffset = 1.0f;
|
||||
|
||||
public override void Cast(MagicAttacks caster, Transform target)
|
||||
{
|
||||
caster.StartCoroutine(CastRoutine(caster, target));
|
||||
}
|
||||
|
||||
private IEnumerator CastRoutine(MagicAttacks caster, Transform target)
|
||||
{
|
||||
// 1. Rotate
|
||||
yield return caster.RotateTowardsTargetRoutine(target, rotationDuration);
|
||||
|
||||
// 2. Wait for animation point
|
||||
yield return new WaitForSeconds(Mathf.Max(0, spawnDelay - rotationDuration));
|
||||
|
||||
// 3. Spawn
|
||||
Vector3 spawnPos = caster.transform.position + caster.transform.forward + Vector3.up * 1.5f;
|
||||
GameObject obj = Instantiate(projectilePrefab, spawnPos, caster.transform.rotation);
|
||||
|
||||
// 4. Aim
|
||||
if (target != null)
|
||||
{
|
||||
Vector3 aimDir = (target.position + Vector3.up * aimHeightOffset) - spawnPos;
|
||||
obj.transform.rotation = Quaternion.LookRotation(aimDir);
|
||||
}
|
||||
|
||||
// 5. Apply Modifiers
|
||||
caster.ApplyDamageModifiers(obj);
|
||||
|
||||
Destroy(obj, lifeTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user