I have been trying to get my player to freeze when the space button has stopped being pressed. This is the code I am using:
void Move()
{
getChangesFromMousePosition();
if (Input.GetKey(KeyCode.Space))
{
rigidbody.constraints = RigidbodyConstraints2D.None;
thrustForward(2);
} else
{
thrustForward(0);
rigidbody.constraints = RigidbodyConstraints2D.FreezePosition;
}
}
This Move() method is in the update() method and is being run. The getChangesFromMousePosition() is working fine and the thrustForward() and if statements are being run. But when i freeze the constraints the player goes from where it is and bounces to the center of the screen then when I press space again it moves from the center and works fine until i freeze it again.