0

I am creating a breakout style game and currently stuck on a particular problem for which I am sure there is a solution but have not been able to figure it out. So there are 3 walls (left, right, and top) and my problem is that when the ball bounces off the left or right wall it then goes on to hit the top wall at an angle which then causes the ball to hit the next wall (left or right) towards the bottom of the wall, this is affecting the intended gameplay I am trying to achieve for my particular version of breakout and is making the game harder to play.

What I am trying to achieve is whenever the ball hits either the left or right for it to then go onto hit the top wall around the centre and then again from the top wall to hit the left or right wall (the opposite of the first wall hit) near its centre and so on. Basically what I want is the ball to go about bouncing of the walls at a regular angle around the centre of each wall.

Unwanted behaviour Unwanted ball bounce

Desired behaviour

Desired ball bounce

Kaz
  • 137
  • 2
  • 3
  • 17
  • If the ball hits a side wall and the y component of its velocity points up, you aim the ball at the middle of the top wall. – Tesseract Dec 03 '16 at 23:40
  • Won't this make your game a little bit boring? Why dont you want to just leave it that way? you are trying to achieve an effect that is not real and it may become too predictable or even not chalenging for players – Haim Bendanan Dec 04 '16 at 00:14
  • Part of the strategy of these breakout games is that the player can manipulate the angle of reflection based on the positioning and movement of the paddle. If you're hard-coding it...that just doesn't sound fun at all. – Serlite Dec 04 '16 at 00:17
  • Actually my paddle is made of three parts (left middle and right), so when the ball hits the left side of the paddle it causes the ball to go towards the left wall via code: col.gameObject.GetComponent ().velocity = new Vector2 (-10f, 10f/*col.gameObject.transform.position.y*/) * GameManager.speed; – Kaz Dec 04 '16 at 01:11
  • paddle is made of three parts (left middle and right), e.g when it hits the left side it causes the ball to go towards the left wall via code: col.gameObject.GetComponent ().velocity = new Vector2 (-10f, 10f) * GameManager.speed; There are other elements in the game that adds complexity to the game I am trying to create. The ball doesn't have to bounce right in the middle of the side walls, as long as it hits near the middle and above will be fine. So which ever part of the wall it hits off the paddle I then want it to hit the middle of the top wall and the next wall too – Kaz Dec 04 '16 at 01:20
  • Hitting a absolutely rigid wall (no lost of energy) , causes one of velocity component to change. If you have velocity v=Vector2(..), that hitting side wall, makes v,X to change sign, hitting top wall, makes v.Y to change sign, To avoid repetition, I suggest to make the wall rigidity random (e.g rand.NextDouble(0.2)+0.8), so you have a set of equations for kinetic energy (lost by random value) and momentum. As about paddle, it can will increase or reduce the energy, depending on how fast the player moves it. Some math is involved there, as I can see, – cyanide Dec 04 '16 at 01:44
  • Thanks for you suggestions, I know the behaviour I want, its just that I don't know how to do it nor the maths involved. What I want is that when the ball hits the paddle and then bounces towards a wall, even if it hits the low end of that wall I want it to then orient itself towards the middle of the top wall and last wall so I am guessing maths will be required to dynamically calculate the vector to make sure its hits the centre of the next two walls. To be honest as long as it hits the final wall towards the centre (before it hits the paddle) then that would be fine for my game. – Kaz Dec 04 '16 at 01:55

0 Answers0