Discuss Scratch

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…

It's time I get a real signature. Oh, by the way, click here my new account. @-gr!
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 projectshow I made the banneranimated 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

dhakabangladesh wrote:

does anyone know how to make a sprite bounce only up and down of off another sprite on scratch?
assuming you want a sprite to collide with one and then bounce up(while being affected by gravity):
...
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
if you meant using a block similair to the “if on edge, bounce” block, that isnt easily possible.

(she/her) Mostly inactive nowadays. stand with ukraine.
MasterofTheBrick
Scratcher
1000+ posts

help

CatGuyAnimates wrote:

...
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
That repeatedly moves the sprite down even if it isn't touching the sprite though…

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

MasterofTheBrick wrote:

CatGuyAnimates wrote:

...
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
That repeatedly moves the sprite down even if it isn't touching the sprite though…

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
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.

(she/her) Mostly inactive nowadays. stand with ukraine.
MasterofTheBrick
Scratcher
1000+ posts

help

CatGuyAnimates wrote:

yes thats the point.
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.

Powered by DjangoBB