this.rBody2D.velocity = this.dir.normalized * this.speed * Time.deltaTime * this.knockbackSpeed;
    protected void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("PlayerBullet"))
        {
            StartCoroutine(KnockbackRoutine(collision.GetComponent<Bullet>().knockbackSpeed));
        }
    }

    protected IEnumerator KnockbackRoutine(float knockbackSpeed)
    {
        this.knockbackSpeed = -knockbackSpeed;
        yield return new WaitForSeconds(0.1f);
        this.knockbackSpeed = 1f;
    }

 

오브젝트의 기존 이동 방향에서 -방향으로 이동하게끔 구현하였다.

 

+ Recent posts