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.