Unity 2D Ball Stuck on wall when bouncing

I’m making a 2D game and when my enemy squares bounce off of a wall, they get stuck in a weird way.


I’m using four walls as boundaries and my enemy prefab is in the inspector screen. When the “ball” bounces, it hits the wall and zig zags up and down along the wall while moving down it. This is my script for moving the ball which might be the problem.

private int moveX;
private int moveY;

// Use this for initialization
void Start () {
moveX = -Random.Range(1, 10);
moveY = -Random.Range(1, 10);
}

// Update is called once per frame
void Update () {
    this.transform.Translate(Vector2.left * moveX * Time.deltaTime);
    this.transform.Translate(Vector2.up * moveY * Time.deltaTime);
}

Can someone tell me what I’m messing up, I’ve tried adding a rigid body to the walls and messing with the bounciness of the square.

Check the physics material(BallBouncer) inside the boxCollider of your ball or the physics material of your platforms. You can see two fields “Bounciness” and “Fricton”. Is there any value of friction? if there is change it to 0

I figured it out, because of the way I was moving the square it was bouncing off the wall but then kept trying to go forward. I’m fixing this problem by using velocity instead of Translate().