4-way version of breakout help needed
Posted 11 May 2012 - 05:40 PM
My problem is trying to get the ball to bounce relative to it's position on the paddle EX: If it hits the left edge of the paddle I want it to ge left.
I don't understand coding that much, however I was able to find someone with a similar problem on another forum: http://gmc.yoyogames...howtopic=538413
I found this piece of code there: direction = (obj_paddle.x - obj_ball.x) +90.
This code solved the problem for my paddle on the bottom of the screen, But my paddles on the right, left, & upper part of the screen still don't have the ball bounce the right way.
Any help would be greatly appreciated.
Posted 11 May 2012 - 07:02 PM
direction = x-other.x + 270;Left paddle:
direction = other.y-y;Right paddle:
direction = y-other.y + 180;It's not the best way to do it because the angle is just based on how wide the paddle is, so you can't control how much it will bounce. And it won't even work if the paddle is too wide.
A better way:
direction = 80*(other.x-x)/(other.sprite_width/2) + 90;Top paddle:
direction = 80*(x-other.x)/(other.sprite_width/2) + 270;Left paddle:
direction = 80*(other.y-y)/(other.sprite_height/2);Right paddle:
direction = 80*(y-other.y)/(other.sprite_height/2) + 180;This way it takes the width/height of the paddle into account and you can specify a maximum angle the ball can bounce to, I used 80 in the example.
I put the code in the Collision events of the ball.
Edited by Locust, 11 May 2012 - 07:15 PM.
Posted 11 May 2012 - 07:12 PM
direction = -(obj_paddle.x - obj_ball.x) -90;For the left and right, you should take the y position instead of the x position.
Your code for the right side would look like this:
direction = (obj_paddle.y - obj_ball.y) +180;the left side would be the negative of this.
didn't see Locust's reply. I think he's correct too.
Edited by troido, 11 May 2012 - 07:15 PM.
Posted 15 May 2012 - 06:20 PM
The game works beautifully now
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users