I am currently using RB2D velocity for movement but I can’t make it stop sliding after I’ve finished pressing the button. It feels like the Ice level from Mario. How do I stop my character sliding everywhere?
My code is:
void Movement() {
if (Input.GetAxisRaw ("Horizontal") > 0.1) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (speed, GetComponent<Rigidbody2D> ().velocity.y);
}
if (Input.GetAxisRaw ("Horizontal") < -0.1) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (-speed, GetComponent<Rigidbody2D> ().velocity.y);
}
if (Input.GetAxisRaw ("Vertical") > 0.5 && grounded) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, jumpHeight);
}
}
My speed is set to 5, jumpHeight is 10 and I have both box collider and RigidBody2D on my player
Thanks for any help in advance