B
B
bad22vk2020-10-26 16:15:35
Unity
bad22vk, 2020-10-26 16:15:35

Physics engine Unity2d. How to make a rebound?

It is necessary to make an elementary rebound of the character when receiving damage.
I was able to make the following code:

if (collision.gameObject.tag == "Vrag")
        {
            gameObject.GetComponent<Rigidbody2D>().AddForce(transform.up * direction * powerForce, ForceMode2D.Impulse);
            TakeDamagee();
            hpText.text = ((int)hp).ToString();
        }


That is, we take damage and the character jumps with a certain force.
But after all, it is necessary that he also moved along X.
I tried to write transform.right , but it didn't work.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question