Character Controler

Hi,
Im a 3d artist starting to learn unity to make mobile games.
Now im trying to make a character controler. I’ve started to make this script with click w to go up, it looks good but when it colides with walls then it goes back.

var ws = 5;

function FixedUpdate () {
	if(Input.GetButtonDown("Vertical"))
	{
		rigidbody2D.AddForce(Vector2.up * ws);
	}
	if(Input.GetButtonUp("Vertical"))
	{
		rigidbody2D.AddForce(Vector2.up * -ws);
	}
}

Thanks,
Lukiszlak.

It’s because the controller is literally bouncing off the walls. Try using a custom physics material and setting the bounciness to zero. Apply it to the collider.

Squared, thanks for ansver but it isnt it. When it hit the collision object then vectr.up is 0 but when we get button up the vector.up is -5 when it needs to be 0.

@edit
I’ve tried with rigidbody2d.sleep it works but its very buggy. Like it dont stop it sometimes when i unclick the key.

var ws = 5;
var wsd = Vector2.up;

function FixedUpdate () {

	if(Input.GetButtonDown("w"))
	{
		rigidbody2D.AddForce(Vector2(0, ws));
	}
	if(Input.GetButtonUp("w"))
	{
		rigidbody2D.Sleep();
	}
	if(Input.GetButtonDown("a"))
	{
		rigidbody2D.AddForce(Vector2(ws, 0));
	}
	if(Input.GetButtonUp("a"))
	{
		rigidbody2D.Sleep();
	}
	if(Input.GetButtonDown("s"))
	{
		rigidbody2D.AddForce(Vector2(0, -ws));
	}
	if(Input.GetButtonUp("s"))
	{
		rigidbody2D.Sleep();
	}
	if(Input.GetButtonDown("d"))
	{
		rigidbody2D.AddForce(Vector2(ws, 0));
	}
	if(Input.GetButtonUp("d"))
	{
		rigidbody2D.Sleep();
	}
}

@up

Please help. I dont have any idea how to do it : (