Discuss Scratch

JBaxter02
Scratcher
22 posts

Making sprites bounce off other sprites?

I know about the “if on edge, bounce” block, but is there a way to make a sprite bounce off of another sprite?
Thanks.
landonwang
Scratcher
72 posts

Making sprites bounce off other sprites?

forever
if <touching [something v] ?> then
point towards [something v]
set [i v] to (direction)
point in direction (((i) * (-1)) + (pick random (-30) to (30)))
end
end

Last edited by landonwang (Jan. 5, 2017 22:21:15)

JBaxter02
Scratcher
22 posts

Making sprites bounce off other sprites?

But that does not take into account the angle of the thing it is bouncing off, though

landonwang wrote:

forever
if <touching [something v] ?> then
point towards [something v]
set [i v] to (direction)
point in direction (((i) * (-1)) + (pick random (-30) to (30)))
end
end

DominoDragon1
Scratcher
1000+ posts

Making sprites bounce off other sprites?

If it is bouncing off of the right or left of the sprite, you can do:
when green flag clicked
forever
move (10) steps
if <touching [Other Sprite] ?> then
point in direction ((direction) * (-1))
move (10) steps
say [This makes it so that the Sprite isn't toughing the other Sprite.]
end
end

I don't know how to do it if it hits on the top/bottom of the second sprite.

Hope this helped!
asivi
Scratcher
1000+ posts

Making sprites bounce off other sprites?

JBaxter02 wrote:

I know about the “if on edge, bounce” block, but is there a way to make a sprite bounce off of another sprite?
Thanks.
Hi, Do you have a project?
MabonBaladevaKain
Scratcher
100+ posts

Making sprites bounce off other sprites?

Here are a few of my projects that bounce one thing off another:

https://scratch.mit.edu/projects/1243174/

https://scratch.mit.edu/projects/1245041/ <——— this one is best

https://scratch.mit.edu/projects/138823380/ <——– but this one is simple
titanscratch
Scratcher
100+ posts

Making sprites bounce off other sprites?

when green flag clicked
forever
move (10) steps
if <touching [Sprite 2 v] ?> then
turn cw (180) degrees // or the other way round
wait (0.25) secs
end
end
DominoDragon1
Scratcher
1000+ posts

Making sprites bounce off other sprites?

titanscratch wrote:

when green flag clicked
forever
move (10) steps
if <touching [Sprite 2 v] ?> then
turn cw (180) degrees // or the other way round
wait (0.25) secs
end
end

This makes it turn completely around, not bounce off of the sprite in a different direction.
asivi
Scratcher
1000+ posts

Making sprites bounce off other sprites?

DominoDragon1 wrote:

titanscratch wrote:

when green flag clicked
forever
move (10) steps
if <touching [Sprite 2 v] ?> then
turn cw (180) degrees // or the other way round
wait (0.25) secs
end
end

This makes it turn completely around, not bounce off of the sprite in a different direction.
Nope, it goes to its opposite direction.
asivi
Scratcher
1000+ posts

Making sprites bounce off other sprites?

JBaxter02 wrote:

But that does not take into account the angle of the thing it is bouncing off, though

landonwang wrote:

forever
if <touching [something v] ?> then
point towards [something v]
set [i v] to (direction)
point in direction (((i) * (-1)) + (pick random (-30) to (30)))
end
end

Where is your project?
Please, instead of say this does such thing or any other thing share what you have attempted.

Last edited by asivi (Jan. 6, 2017 12:57:16)

asivi
Scratcher
1000+ posts

Making sprites bounce off other sprites?

LUKYLIAM13994
Scratcher
1 post

Making sprites bounce off other sprites?

,mn
Scratch-Minion
Scratcher
1000+ posts

Making sprites bounce off other sprites?

This project demonstrates how to calculate a rebound angle off a horizontal or vertical surface: https://scratch.mit.edu/projects/138052902/
If you want to rebound off surfaces that are inclined at other angles, see this excellent project https://scratch.mit.edu/projects/99412537/ by @deck26

——————-

If you have roughly circular objects that collide, you could use the algorithm below provided they do not overlap too much when collision is detected.
The algorithm calculates the direction of a tangent to Object 2 at the point of collision, then rebounds Object 1 off this tangent line.

- In Object 1, the object being hit (or an invisible object at the same position)

point towards [Object 2 v]
turn cw (90) degrees
set [Tangent Direction v] to (direction)

- Then in Object 2, the moving object that hits Object 1

point in direction (((2) * (Tangent Direction)) - (direction))
RedFaceplant
Scratcher
48 posts

Making sprites bounce off other sprites?

I normally just have a common colored dot or line (say black) on the top of the bottom sprite, then that will give you the ability to use
<touching color [#222222] ?>
(set the color to the dot on top)
deck26
Scratcher
1000+ posts

Making sprites bounce off other sprites?

cs1334240 wrote:

asdadsdsadsadadadseaadasasasasssasdasdasdda

RedFaceplant wrote:

I normally just have a common colored dot or line (say black) on the top of the bottom sprite, then that will give you the ability to use
<touching color [#222222] ?>
(set the color to the dot on top)
Please don't spam or necropost.

Powered by DjangoBB