I’m writing a simple 2d game and want the player to be hit back if something hit it, Just get the velocity of the hitting object and applying an opposite impulse force to the player. But that doesn’t work. But what i find weird is when i choose to use AddForce to control my character, all my previous code will work perfect fine. So i guess there’re some problems with Unity Engine…
And what make me annoying is it’s not suitable to control player using AddForce, cause it will be accelerating so that not a willing move= =.
Really annoyed by this, please help me out guys. Thanks!
Finally work it out, seems you can’t call AddForce() inside a function other than FixedUpdate(or maybe Update). So i keep using velocity to control my player and as long as hit by a moving object, call pushback function and then lead to the calling of Impluse Addforce on player’s Rigidbody inside the FixedUpdate of plyerController.