Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Sprite moving with another.
- crystalbeastpikachu
-
36 posts
Sprite moving with another.
Let me cut to the chase; I want a sprite to move upwards/downwards with the other, but it's not working! Here are the scripts:
Bouncy ball (Thing that's moving):
Thing that's moving with the Bouncy ball:
Someone please help!
Bouncy ball (Thing that's moving):
when gf clicked
go to x:(0) y:(0)
repeat until (((y position) = [170]) or ((y position) > [170]))
change y by (3)
wait [1.0E-14] secs
end
forever
if (((y position) = [170]) or ((y position) > [170])) then
repeat until (((y position) = [-170]) or ((y position) < [-170]))
change y by (-3)
wait [1.0E-14] secs
end
end
if (((y position) = [-170]) or ((y position) < [-170])) then
repeat until (((y position) = [170]) or ((y position) > [170]))
change y by (3)
wait [1.0E-14] secs
end
end
end
when gf clicked
forever
set [bouncy ball position v] to (y position)
end
Thing that's moving with the Bouncy ball:
when gf clicked
forever
if ((([y position v] of [bouncy ball v]) = [170]) or (([y position v] of [bouncy ball v]) > [170])) then
repeat until ((([y position v] of [bouncy ball v]) = [-170]) or (([y position v] of [bouncy ball v]) < [-170]))
set y to ((bouncy ball position) - (50))
end
end
if ((([y position v] of [bouncy ball v]) = [-170]) or (([y position v] of [Sprite2 v]) < [-170])) then
repeat until ((([y position v] of [bouncy ball v]) = [170]) or (([y position v] of [bouncy ball v]) > [170]))
set y to ((bouncy ball position) + (50))
end
end
end
Someone please help!
Last edited by crystalbeastpikachu (Sept. 15, 2013 21:56:04)
when gf clicked
set [verb v] to [Eat/Dance/Game/Scratch]
say (join [Keep calm and ] (join (verb) [ On] ))
- Splodgey
-
100+ posts
Sprite moving with another.
You put
if ((([y position v] of [bouncy ball v]) = [170]) or (([y position v] of [bouncy ball v]) = [170])) thenI think you mean
if ((([y position v] of [bouncy ball v]) = [170]) or (([y position v] of [bouncy ball v]) > [170])) then
Ever wondered why there's no text box? Or why you can make sprites “say” stuff, but not display pure text? Click here! Now v1.3, includes links!
Text Box, Calculator, AlphaSorter & Case Sensor
Have a large-scale Minecraft project and you want to know how much raw materials you need to craft the “ingredients”? Click here!
![](http://imageshack.us/scaled/thumb/703/ptd.png)
![](http://imageshack.us/scaled/thumb/22/u7z.png)
Minecraft PvP Weapon Vs Armour Calculator/Simulator
- drmcw
-
1000+ posts
Sprite moving with another.
That seem so much unnecessary code. For the ball;
for the follower
point in direction [0 v]
forever
move (3) steps
if on edge bounce
end
for the follower
forever
set y to ([y position v] of [ball sprite v])
end
- ErnieParke
-
1000+ posts
Sprite moving with another.
Oh, this should be simple, and you're actually overcomplicating this. Just use this simple script:
That will move the bouncy ball above your first sprite. And if you want to move it to the left/right, you'll have to add in another variable, just like (bouncy ball position), but with the x Position now. Or are you wanting something else?
By the way, if you'd like to see a project in action, you could visit this project.
With regards,
ErnieParke
when gf clicked
forever
set y to ((bouncy ball position) + (50))
That will move the bouncy ball above your first sprite. And if you want to move it to the left/right, you'll have to add in another variable, just like (bouncy ball position), but with the x Position now. Or are you wanting something else?
By the way, if you'd like to see a project in action, you could visit this project.
With regards,
ErnieParke
- crystalbeastpikachu
-
36 posts
Sprite moving with another.
That seem so much unnecessary code. For the ball;point in direction [0 v]
forever
move (3) steps
if on edge bounce
end
for the followerforever
set y to ([y position v] of [ball sprite v])
end
Then it would'n't work, after the sprites reach the top, they'll stay there.
Oh, this should be simple, and you're actually overcomplicating this. Just use this simple script:when gf clicked
forever
set y to ((bouncy ball position) + (50))
That will move the bouncy ball above your first sprite. And if you want to move it to the left/right, you'll have to add in another variable, just like (bouncy ball position), but with the x Position now. Or are you wanting something else?
By the way, if you'd like to see a project in action, you could visit this project.
With regards,
ErnieParke
I want the thing that follow's the bouncy ball to go lower when the ball is going down.
You putif ((([y position v] of [bouncy ball v]) = [170]) or (([y position v] of [bouncy ball v]) = [170])) thenI think you meanif ((([y position v] of [bouncy ball v]) = [170]) or (([y position v] of [bouncy ball v]) > [170])) then
Fixed it. Also, applied to my test, but it can only go down.
Last edited by crystalbeastpikachu (Sept. 15, 2013 21:57:25)
when gf clicked
set [verb v] to [Eat/Dance/Game/Scratch]
say (join [Keep calm and ] (join (verb) [ On] ))
- drmcw
-
1000+ posts
Sprite moving with another.
That seem so much unnecessary code. For the ball;point in direction [0 v]
forever
move (3) steps
if on edge bounce
end
for the followerforever
set y to ([y position v] of [ball sprite v])
end
Then it would'n't work, after the sprites reach the top, they'll stay there.
have you tried it? I think you'll find it will bounce because of the if on edge bounce block!
- crystalbeastpikachu
-
36 posts
Sprite moving with another.
That seem so much unnecessary code. For the ball;point in direction [0 v]
forever
move (3) steps
if on edge bounce
end
for the followerforever
set y to ([y position v] of [ball sprite v])
end
Then it would'n't work, after the sprites reach the top, they'll stay there.
have you tried it? I think you'll find it will bounce because of the if on edge bounce block!
Even though it bounces, it still points in direction 0
when gf clicked
set [verb v] to [Eat/Dance/Game/Scratch]
say (join [Keep calm and ] (join (verb) [ On] ))
- drmcw
-
1000+ posts
Sprite moving with another.
That seem so much unnecessary code. For the ball;point in direction [0 v]
forever
move (3) steps
if on edge bounce
end
for the followerforever
set y to ([y position v] of [ball sprite v])
end
Then it would'n't work, after the sprites reach the top, they'll stay there.
have you tried it? I think you'll find it will bounce because of the if on edge bounce block!
Even though it bounces, it still points in direction 0
No, the bounce block will change the direction otherwise it wouldn't bounce. It's not many blocks, why don't you try it?
If you want the follower to change its direction too then you can add to its loop;
point in direction ([direction v] of [ball sprite v] )
Last edited by drmcw (Sept. 15, 2013 22:17:45)
- crystalbeastpikachu
-
36 posts
Sprite moving with another.
That seem so much unnecessary code. For the ball;point in direction [0 v]
forever
move (3) steps
if on edge bounce
end
for the followerforever
set y to ([y position v] of [ball sprite v])
end
Then it would'n't work, after the sprites reach the top, they'll stay there.
have you tried it? I think you'll find it will bounce because of the if on edge bounce block!
Even though it bounces, it still points in direction 0
No, the bounce block will change the direction otherwise it wouldn't bounce. It's not many blocks, why don't you try it?
If you want the follower to change its direction too then you can add to its loop;point in direction ([direction v] of [ball sprite v] )
I want to make go to the side, too, so that won't work.
when gf clicked
set [verb v] to [Eat/Dance/Game/Scratch]
say (join [Keep calm and ] (join (verb) [ On] ))
- drmcw
-
1000+ posts
Sprite moving with another.
That's not what you asked initially, but It will if you point it in the right direction and you could just use go to ball sprite! .That seem so much unnecessary code. For the ball;point in direction [0 v]
forever
move (3) steps
if on edge bounce
end
for the followerforever
set y to ([y position v] of [ball sprite v])
end
Then it would'n't work, after the sprites reach the top, they'll stay there.
have you tried it? I think you'll find it will bounce because of the if on edge bounce block!
Even though it bounces, it still points in direction 0
No, the bounce block will change the direction otherwise it wouldn't bounce. It's not many blocks, why don't you try it?
If you want the follower to change its direction too then you can add to its loop;point in direction ([direction v] of [ball sprite v] )
I want to make go to the side, too, so that won't work.
- crystalbeastpikachu
-
36 posts
Sprite moving with another.
That's not what you asked initially, but It will if you point it in the right direction and you could just use go to ball sprite! .That seem so much unnecessary code. For the ball;point in direction [0 v]
forever
move (3) steps
if on edge bounce
end
for the followerforever
set y to ([y position v] of [ball sprite v])
end
Then it would'n't work, after the sprites reach the top, they'll stay there.
have you tried it? I think you'll find it will bounce because of the if on edge bounce block!
Even though it bounces, it still points in direction 0
No, the bounce block will change the direction otherwise it wouldn't bounce. It's not many blocks, why don't you try it?
If you want the follower to change its direction too then you can add to its loop;point in direction ([direction v] of [ball sprite v] )
I want to make go to the side, too, so that won't work.
I do'n't want the thing that follow's the bouncy ball to actually go to the ball either, I just want them to have the same y position. sorry for the tall order.
Last edited by crystalbeastpikachu (Sept. 15, 2013 22:42:49)
when gf clicked
set [verb v] to [Eat/Dance/Game/Scratch]
say (join [Keep calm and ] (join (verb) [ On] ))
- drmcw
-
1000+ posts
Sprite moving with another.
Then just use the first script I wrote. You don't have to start the ball pointing straight up but can point it whatever direction you want, I only put that in because most sprites default to pointing right so there would be no up/down movement at all..That's not what you asked initially, but It will if you point it in the right direction and you could just use go to ball sprite! .That seem so much unnecessary code. For the ball;point in direction [0 v]
forever
move (3) steps
if on edge bounce
end
for the followerforever
set y to ([y position v] of [ball sprite v])
end
Then it would'n't work, after the sprites reach the top, they'll stay there.
have you tried it? I think you'll find it will bounce because of the if on edge bounce block!
Even though it bounces, it still points in direction 0
No, the bounce block will change the direction otherwise it wouldn't bounce. It's not many blocks, why don't you try it?
If you want the follower to change its direction too then you can add to its loop;point in direction ([direction v] of [ball sprite v] )
I want to make go to the side, too, so that won't work.
I do'n't want the thing that follow's the bouncy ball to actually go to the ball either, I just want them to have the same y position. sorry for the tall order.
- crystalbeastpikachu
-
36 posts
Sprite moving with another.
Then just use the first script I wrote. You don't have to start the ball pointing straight up but can point it whatever direction you want, I only put that in because most sprites default to pointing right so there would be no up/down movement at all..That's not what you asked initially, but It will if you point it in the right direction and you could just use go to ball sprite! .That seem so much unnecessary code. For the ball;point in direction [0 v]
forever
move (3) steps
if on edge bounce
end
for the followerforever
set y to ([y position v] of [ball sprite v])
end
Then it would'n't work, after the sprites reach the top, they'll stay there.
have you tried it? I think you'll find it will bounce because of the if on edge bounce block!
Even though it bounces, it still points in direction 0
No, the bounce block will change the direction otherwise it wouldn't bounce. It's not many blocks, why don't you try it?
If you want the follower to change its direction too then you can add to its loop;point in direction ([direction v] of [ball sprite v] )
I want to make go to the side, too, so that won't work.
I do'n't want the thing that follow's the bouncy ball to actually go to the ball either, I just want them to have the same y position. sorry for the tall order.
Your right, it worked! Sorry for not trying earlier.
when gf clicked
set [verb v] to [Eat/Dance/Game/Scratch]
say (join [Keep calm and ] (join (verb) [ On] ))
- Discussion Forums
- » Help with Scripts
-
» Sprite moving with another.