Hello,
I’m making a bullet hell inspired game which require very precise control of character movement. I do want use a RigidBody over direct manipulation of transform.position because there will be some physics based collisions in the game. However, when the player stops pressing the arrow keys, I want the character to come to a complete stop instantly. Currently, the character comes to a stop more gradually, as if they are decelerating. I have tried doing things like increasing the drag, but that seems to just generally slow the character down. Here is the relevant code from my fixedUpdate:
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
float horizontalspeed = moveHorizontal * maxSpeed;
float verticalspeed = moveVertical * maxSpeed;
//print (moving);
if(moveHorizontal!=0 && moveVertical !=0)
{
horizontalspeed = horizontalspeed/Mathf.Sqrt(2);
verticalspeed = verticalspeed/Mathf.Sqrt(2);
}
if (Input.GetKeyUp ("up") || Input.GetKeyUp ("down")) {
print ("keyup");
rigidbody2D.velocity = new Vector2 (horizontalspeed, 0f);
}
else
rigidbody2D.velocity = new Vector2 (horizontalspeed, verticalspeed);
You can see that right now I’m testing just the vertical axis for a fix. I pass the vertical component of the Vector2 “0” when the key comes up. However despite this, it’s velocity still does not instantly drop to 0, instead it falls off. I don’t understand why at all. Any insight on how to fix this would be greatly appreciated. Thanks!