1. 넉백 구현하기
○ TopDownMovement 수정
--------------------- 생략 ---------------------
private Vector2 knockback = Vector2.zero;
private float knockbackDuration = 0.0f;
private void FixedUpdate()
{
ApplyMovment(movementDirection);
if(knockbackDuration > 0.0f)
{
knockbackDuration -= Time.fixedDeltaTime;
}
}
--------------------- 생략 ---------------------
public void ApplyKnockback(Transform other, float power, float duration)
{
knockbackDuration = duration;
knockback = -(other.position - transform.position).normalized * power;
}
private void ApplyMovment(Vector2 direction)
{
direction = direction * characterStatHandler.CurrentStat.speed;
if(knockbackDuration > 0.0f)
{
direction += knockback;
}
movementRigidbody.velocity = direction;
}