Discuss Scratch

klobbo
Scratcher
11 posts

how do I make realistic bouncing?

Right now the script is:

if <touching [Edge] ?> then
turn cw (180) degrees
end

This is ok, but it makes the object turn around instead of bouncing correctly, and everything else I've tried makes it turn around at some point. I want it to bounce around the screen somewhat like the dvd logo. How can I do this?
mmhmBeans
Scratcher
500+ posts

how do I make realistic bouncing?

Already answered at #66388.
NeonG4
Scratcher
1000+ posts

how do I make realistic bouncing?

klobbo wrote:

Right now the script is:

if <touching [Edge] ?> then
turn cw (180) degrees
end

This is ok, but it makes the object turn around instead of bouncing correctly, and everything else I've tried makes it turn around at some point. I want it to bounce around the screen somewhat like the dvd logo. How can I do this?
In this case, couldn't the
if <touching [Edge] ?> then
turn cw (180) degrees
end
be switched for
if on edge, bounce
block?
platypus3333
Scratcher
37 posts

how do I make realistic bouncing?

An easy solution for a directional bounce is this:
forever
if <touching [ v] ?> then
point in direction ((direction) * (-1))
end
end
If you want a straight bounce you could do this:
forever
move (steps) steps
change [ steps] by (1)
if <touching [ v] ?> then
turn ccw (180) degrees
set [ steps] to [0]
end
end
You can customize it to make faster or slower movement.

Last edited by platypus3333 (June 12, 2023 20:12:44)

NeonG4
Scratcher
1000+ posts

how do I make realistic bouncing?

platypus3333 wrote:

An easy solution for a bounce is this:
point in direction ( ((direction) * (-1)))
This only works for verticle walls.
A horizontal wall with a direction of 91 would become -91, which still is on the wall.
platypus3333
Scratcher
37 posts

how do I make realistic bouncing?

NeonG4 wrote:

platypus3333 wrote:

An easy solution for a bounce is this:
point in direction ( ((direction) * (-1)))
This only works for verticle walls.
A horizontal wall with a direction of 91 would become -91, which still is on the wall.

Your right! I had made a pong game and was thinking of what I used for the paddle and ball bounce.
klobbo
Scratcher
11 posts

how do I make realistic bouncing?

NeonG4 wrote:

klobbo wrote:

Right now the script is:

if <touching [Edge] ?> then
turn cw (180) degrees
end

This is ok, but it makes the object turn around instead of bouncing correctly, and everything else I've tried makes it turn around at some point. I want it to bounce around the screen somewhat like the dvd logo. How can I do this?
In this case, couldn't the
if <touching [Edge] ?> then
turn cw (180) degrees
end
be switched for
if on edge, bounce
block?

wow haha. I didn't even know that block existed. thanks!
platypus3333
Scratcher
37 posts

how do I make realistic bouncing?

NeonG4 wrote:

klobbo wrote:

Right now the script is:

if <touching [Edge] ?> then
turn cw (180) degrees
end

This is ok, but it makes the object turn around instead of bouncing correctly, and everything else I've tried makes it turn around at some point. I want it to bounce around the screen somewhat like the dvd logo. How can I do this?
In this case, couldn't the
if <touching [Edge] ?> then
turn cw (180) degrees
end
be switched for
if on edge, bounce
block?
Actually, no. They do different things. The turn block sends it back to where it came from. The bounce block will make it change the direction by -1.
NeonG4
Scratcher
1000+ posts

how do I make realistic bouncing?

platypus3333 wrote:

snip
Yes, you are very right. However:
1) The topic is resolved.
2) The “if on edge bounce” is what @klobbo was looking for, and not the “turn 180 degrees” block.

Powered by DjangoBB