Project_WL/Assets/Script/Character/Projectile/Projectile/Projectile_Homing.cs

45 lines
1.4 KiB
C#

using System.Collections;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;
public class Projectile_Homing : ProjectileBase
{
public float speed = 10f; // 기본 속도
[Header("유도력(높을수록 강한 유도)")]
public float homingStrength = 5f; // 유도력 조절 변수
public override void Set(ProjectileData _data)
{
base.Set(_data);
StartCoroutine(Co_Update());
}
IEnumerator Co_Update()
{
while (m_ProjecTileData.LifeTime > 0)
{
if (m_ProjecTileData.shooter.isTarget)
{
// 목표 방향 계산
Vector3 direction = (m_ProjecTileData.target.Get_Center_position() - transform.position).normalized;
// 현재 방향을 목표 방향으로 보간 (유도력 적용)
Vector3 newDirection = Vector3.Lerp(transform.forward, direction, homingStrength * Time.deltaTime).normalized;
// 새로운 방향으로 이동
transform.position += newDirection * speed * Time.deltaTime;
// 투사체가 이동하는 방향을 바라보도록 회전
transform.forward = newDirection;
yield return null;
m_ProjecTileData.LifeTime -= Time.deltaTime;
}
else
break;
}
Off(true);
}
}