- Home /
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.
Does the ball or the walls have friction applied as part of any physics material?
Answer by supertimeal · Sep 02, 2016 at 04:25 AM
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().
Answer by Dream_in_code · Sep 01, 2016 at 03:40 PM
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
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to make ball bounce off screen boundaries? 1 Answer
ricochet bounce effect issue 1 Answer
Flat 2D bounce against gravity? 2 Answers