I have a character and an enemy, when a character touches an enemy, or is in it, he is pushed out of him with the help of AddForce() , but this happens rather slowly, as if you are squeezing toothpaste from a tube.

How to make a character in contact with the enemy sharply repelled from him, but at the same time for a short distance (ie, he sharply "bounced" from the enemy, but not for a long distance), I just need one idea, like to do. I tried to simply enlarge Vector2 in the AddForce() function, but the character flew away to warm edges :)

PS Rigidbody2D and CircleCollider2D hang on both objects.

  • one
    ForceMode.Impulse second parameter, not? - Fat-Zer
  • If it flies away, but then stops, then it is inhibited by the medium. Consequently, this force in such a situation should be dramatically increased, and the best (if possible) to make it proportional to the exponent of the distance from the "enemy". - avp 8:50 pm
  • Yes, I used ForceMode.Impulse. I sort of understood what you are talking about, a little googling about environmental resistance, and found the drag function, try to "pick it up" with it. - Intro Games

1 answer 1

Using Drag in Rigidbody helped solve the problem, to the character I apply an impulse with a vector (300, 300) and a value of Drag = 5 , plus the character gravityScale the character increased at that moment, which led to the desired result. The character bounced off a short distance in the right direction.