I’ve been trying to make a Sonic rip-off (2D), and I have a Shadow the Hedgehog style ring system (only lose 10 rings at a time). However, whenever Sonic touches an enemy he loses all his rings due to repeatedly touching the enemy. How can I add StH1 style knockback so he moves away from the enemy?
If you are using a rigidbody2D, you can use the AddForce(Force, ForceMode2D.Impulse) to add a force in the opposite direction form the enemy (transform.position - Enemy.transform.position). I would also recommend adding a system to add temporary invincibility using Coroutines.
Documentation for AddForce and Coroutines:
Always check the documentation. It almost always has the answer.
Hi, Thank you for your answer, however, it did cause more problems. A. for some reason, Sonics speed is now slowed down greatly (I have built in acceleration). B. The knockback hasn’t worked for me, I changed the thrust of the knockback but it still didn’t work. I don’t understand the speed issue (though the knockback could be due to my inexperience). Does anyone know why these are happening?
Thanks in advance!