Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » help
- dhakabangladesh
- Scratcher
29 posts
help
does anyone know how to make a sprite bounce only up and down of off another sprite on scratch?
- WindowsWhiz1234
- Scratcher
100+ posts
help
I believe this belongs in Help with Scripts. Requesting to be moved there…
- griefercube
- Scratcher
500+ posts
help
what do you mean? Please elaborate.
sometimes, you just have to change a way of thinking to solve a problem. -griefercube
|other projects■how I made the banner■animated thumbnails?■i’m on wiki!■Cubey Mines|
|other projects■how I made the banner■animated thumbnails?■i’m on wiki!■Cubey Mines|
Last edited by griefercube (32th Undecimber, XXXX)
https://turbowarp.org/563693837/editor (something i did a while back don’t worry it’s for the banner)
list of working bbcodes:
[color=]
[scratchblocks]
[url=]
[img]
[center]
[code]
[code=]
[list]
[quote]
[b]
[i]
[u]
[s]
[big]
[small]
[p]
[wiki]
[google]
- CatGuyAnimates
- Scratcher
100+ posts
help
assuming you want a sprite to collide with one and then bounce up(while being affected by gravity): does anyone know how to make a sprite bounce only up and down of off another sprite on scratch?
...if you meant using a block similair to the “if on edge, bounce” block, that isnt easily possible.
repeat until <> // leaving the repeat until blank makes it function like a forever loop, but you can stop it if u need to later in the project
change [y-momentum v] by (-1) // y-momentum is the speed on the y axis(up/down). lowering it by 1 each frame mimics gravity
change y by (y-momentum) // this moves the sprite at an increasing speed while falling, and a decreasing speed while moving up
if <touching [thing v]> then // if we hit the other sprite, we need to bounce
set [y-momentum v] to (5) // by setting the momentum to 5, it would move a total of 15 pixels up before beginning to fall again. feel free to adjust
end
end
(she/her) Mostly inactive nowadays. stand with ukraine.
- MasterofTheBrick
- Scratcher
1000+ posts
help
That repeatedly moves the sprite down even if it isn't touching the sprite though…...
repeat until <> // leaving the repeat until blank makes it function like a forever loop, but you can stop it if u need to later in the project
change [y-momentum v] by (-1) // y-momentum is the speed on the y axis(up/down). lowering it by 1 each frame mimics gravity
change y by (y-momentum) // this moves the sprite at an increasing speed while falling, and a decreasing speed while moving up
if <touching [thing v]> then // if we hit the other sprite, we need to bounce
set [y-momentum v] to (5) // by setting the momentum to 5, it would move a total of 15 pixels up before beginning to fall again. feel free to adjust
end
end
forever
if <touching [sprite v] ?> then //initiates the jumping script when they collide
set [y vel v] to [10]
repeat (20)
change y by (y vel)
change [y vel v] by (-1)
end
end
end
- CatGuyAnimates
- Scratcher
100+ posts
help
yes thats the point. also you might want to switch your “repeat 20” with a “repeat 21” otherwise it will move up 1 pixel each time it bounces.That repeatedly moves the sprite down even if it isn't touching the sprite though…...
repeat until <> // leaving the repeat until blank makes it function like a forever loop, but you can stop it if u need to later in the project
change [y-momentum v] by (-1) // y-momentum is the speed on the y axis(up/down). lowering it by 1 each frame mimics gravity
change y by (y-momentum) // this moves the sprite at an increasing speed while falling, and a decreasing speed while moving up
if <touching [thing v]> then // if we hit the other sprite, we need to bounce
set [y-momentum v] to (5) // by setting the momentum to 5, it would move a total of 15 pixels up before beginning to fall again. feel free to adjust
end
endforever
if <touching [sprite v] ?> then //initiates the jumping script when they collide
set [y vel v] to [10]
repeat (20)
change y by (y vel)
change [y vel v] by (-1)
end
end
end
(she/her) Mostly inactive nowadays. stand with ukraine.
- MasterofTheBrick
- Scratcher
1000+ posts
help
That would make the object continually move downwards, even if it was somewhere else on the screen (aka not above the sprite that activates the bounce), or even if the object wasn't in the process of bouncing at all. You're assuming that once the object starts bouncing, it repeatedly does so throughout the duration of the project, without taking into account that the bouncing object might have movement scripts of its own. yes thats the point.
- Discussion Forums
- » Help with Scripts
- » help