Hey, I have tried for some time now to create a script that makes my player not to be pushed by the addForce when i hold down a key. So far I haven’t found a good solution on how to do this.
What I want: addForce is automatically added to the player, so it pushes the player along the screen. But when I press a key (for example F) I want the player to completely stop in the period the button is held down.
What I have tried, and what works in some degree:
void FixedUpdate () {
if(Input.GetKeyDown(KeyCode.F)){
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
rigidbody.Sleep();
}
else{
rigidbody.AddForce(acceleration, 0f, 0f, ForceMode.Acceleration); //This pushes the player with addForce
}
}
Problem here is that it won’t hold back the character for a long period, but only stops it for one frame.
How my game looks like at the moment: - YouTube
Thanks for any kind of help and suggestions