I'm trying to make a game where you draw a line and then you press space and a ball falls from the top left of the screen and rolls along it realistically. There will then be a tub that the ball must fall into. I am doing this on byob but (for people who haven't used it) it contains all the blocks in scratch. I've tried several times from different aproaches but can never get it. The drawing bit is easy, but can someone please help with the inetaction of the ball and the line.
Offline
Well, here goes my guess.
You need to put it so that you have a variable that's named "is_Rolling?",
then you need to have it roll if "is_Rolling?" is equal to yes.
You need to also specify of its rolling in the -x direction to roll counter clockwise. you can use a Boolean variable for that.
so, here's an example:
when gf clicked forever if < <[is_Rolling?]> = <[yes]> > turn cw (15) degrees // or how ever much you want. endThen, make this script:
when i receive [start_Ball v] set [is_Rolling? v] to (yes)Once the ball is stopped, you then need to set "is_Rolling?" to no.
when i receive [ball_Stopped v] set [is_Rolling? v] to (no)Now, about the following the line, i really don't yet know how to make it stop falling, but here's an idea:
when gf clicked change y by (-5)Then, this:
when gf clicked forever if < <touching [line v] ?> > // you also need to specify "tub" with an "or" operator. change y by (5)You could also use another variable and make a script that sets "touching_Line?"
Offline
Thanks CAA14, what about a way to detect which side of the ball the line is on, I tried making lists of all th x and y coordinates of the line but that didn't work, any suggestions for that because if I can get that I can make it move along, just without momentum but I can add that in later?
Offline
Hmmmm.....
Could you clarify a little?
When you say, "Which side of the ball the line is on", do you mean which way the ball is facing on the line?
If that's what you mean, then try this:
if < <[direction] = [90]> > // right. your script here end if < <[direction] = [-90]> > // left. your script here endThat (In theory,) should work.
Offline
What I mean is:
Imagine that the line is in a mountain shape, if you place te ball on the top, it wouldn't move, but if it was slightly to one side it would start to roll down the mountain. My problem is that a script that would make it roll down one side of the mountain, may not necessarily make it roll down the other side. The problem is basically working out what is a left-facing slope as opposed to a right-facing slope.
Thanks for any help in advance.
Offline
Hmmm.... I'm not totally sure how to do that... That sounds like something you'd do in a 3d editor.
Well, here's my last idea:
You need to make a variable called "ground_Level" or something like that.
Then set it's value to the "floor" y concordance.
Then have a script like this:
when gf clicked forever if < [y position] = [ground_Level] > change y by (10) end end
when gf clicked forever if < not < [y position] = [ground_Level]> > change y by (-10) end endThis will get it to fall. Now about having it follow the line, you might try to do the same as the first block, Only 30 y instead of 10. Though this is all a guess as scratch doesn't have (as far as i know,) a good way to do physics.
Offline
CAA14 wrote:
Hmmm.... I'm not totally sure how to do that... That sounds like something you'd do in a 3d editor.
Well, here's my last idea:
You need to make a variable called "ground_Level" or something like that.
Then set it's value to the "floor" y concordance.
Then have a script like this:when gf clicked forever if < (y position) = [ground_Level] > change y by (10) endwhen gf clicked forever if < not < (y position)= [ground_Level]> > change y by (-10) endCAA14
Fixed a bit.
Offline
I was thinking something along the lines of: you draw a line and all the x and y coordiantes of the line go into a list (one for x and one for y) then the computer works out the angles between them. Then if the ball is touching the line, it works out which bit of the line it is touching (and therefore what angles) and bounces off it. The bouncing is trigonometry and momentum which isn't that hard, relatively, but the angles and detecting which part of the line has been touched is difficult.
Offline
Thanks for fixing my blocks, Ernie.
Well, I don't know trig, so I can help you there.
Hopefully you or someone else can think of something that works, because I don't have any other ideas...sorry.
Regards,
CAA14
Offline
Thanks CAA14, I've managed to get my maths teacher to talk me through trigonometry and vector projection, though it's not exactly easy, so I should be O.K. But if anyone does have an idea please post because I'm intending on spending ages doing this and making it look really good.
Offline