Pages: 1
Topic closed
For a school assignment i have to make a game, i have finished everything except i cant make the ball bounce off the bar. Even my digital teacher cant figure it out, if you have any answers i need them desperatly thanks
Offline
If you need it to just bounce up and down, you can use this in place of the "if on edge bounce" block:
Do you need it to bounce on all four sides? If you do I can write a longer explanation.
Last edited by Kileymeister (2011-06-21 22:04:15)
Offline
Yes please it didnt work the way i wanted it to. Im trying to bounce the ball off a paddle, like the game pong and it just moved to the side slighty but still went through the paddle?
Offline
Perhaps it's repeatedly sensing the bar and turning. Try this (make it a separate script):
Edit: Is your paddle facing like this _ or like this | ?
Last edited by Kileymeister (2011-06-21 22:17:39)
Offline
Hm, maybe I think your paddle is facing a different direction.
Last time, try this:
Offline
Do you have a project posted on the Scratch site that we can look at? It's hard to describe potential solutions without knowing how you are moving the "ball".
One possibility:
I'll assume that your ball is traveling across the screen in response to a velocity variable, I'll call that "Vx". And that the paddle moves up and down based on user input. Each time the movement script loops thru, you would change the xposition of the ball by Vx, and look for a condition where the ball is 'hitting' the paddle. You could test for this by checking to see how close the xposition of the ball is to the xposition of the paddle. You would also want to check to see if the yposition of the paddle and ball are close enough to mean that the ball is "hitting" the paddle.
If (xposition(ball)) > ((xposition(paddle)) - 5) AND (abs (ypostion (ball)) - (abs (yposition paddle) < 1/2(paddle width) then
set Vx to Vx - .5
You will have to fill in the 'paddle width' and decide how much to change the ball's velocity. I suggested subtracting 5 from the paddle position to account for its thickness, you can adjust that number to suit. The ball can't go "thru" the paddle using this scheme, as anytime that it is to the right of the paddle, it's "Vx" variable will be decreased until it starts heading back to the left.
Offline
If you can post a project on-line, there are people who will help figure out what the problem is. "Doesn't work" doesn't tell us anything useful to give you assistance - I'm unclear on what you are trying to do.
Offline
Dont worry I figured it out by going on to other questions answers, thanks anyways. Its up on my page if you want to see what I was trying to do (its not a very good game, it was my first thing on scratch so dont judge)
Offline
Topic closed
Pages: 1