Discuss Scratch

SharpHacker77
Scratcher
1 post

How can I make a sprite bounce off another sprite depending on the direction?

need this for a project im working on
HopperSpaniel
Scratcher
60 posts

How can I make a sprite bounce off another sprite depending on the direction?

Could you please explain further on what you want help with? Maybe a link to the project?
kooqle
Scratcher
100+ posts

How can I make a sprite bounce off another sprite depending on the direction?

So, there's a few ways to do this, though they differ.

1. Moving the sprite

when green flag clicked
set [velocity v] to [20]
if <[0] < (velocity)> then
point in direction ( whatever v)
move (velocity) steps
change [ velocity v] by (-0.05)
end
bounce

2. Bouncing

define bounce
if <touching [ rectangle v] ?> then
turn ccw (180) degrees
set [ velocity v] to ((velocity) + (1))
repeat (10)
move (velocity) steps
change [ my variable v] by (-0.05)
end
end

3. Example project



This isn't highly polished, but it's a nice start that everyone can hopefully modify.

Good luck and keep scratching!
Kooqle

Last edited by kooqle (Jan. 15, 2025 10:59:08)

deck26
Scratcher
1000+ posts

How can I make a sprite bounce off another sprite depending on the direction?

Note that turning 180 degrees is not a sensible way to bounce - it only makes sense if the moving sprite approaches the surface it is bouncing off at an angle perpindicular to that surface. Imagine playing pool/snooker if the ball always bounced off a cushion back towards you!

A realistic bounce depends on both the approach angle and the angle of the surface as shown here https://scratch.mit.edu/projects/99412537

MELP_JV
Scratcher
2 posts

How can I make a sprite bounce off another sprite depending on the direction?

ya this would not work (he made me waste 5min trying to figure out y it wasn't working
BENJAMINPICKLE
New Scratcher
1 post

How can I make a sprite bounce off another sprite depending on the direction?

does not work
TutoeTurtle
Scratcher
100+ posts

How can I make a sprite bounce off another sprite depending on the direction?

There's a great griffpatch video about bouncing physics. I recommend you check it out.
Uniquenees
Scratcher
1 post

How can I make a sprite bounce off another sprite depending on the direction?

this does NOT work don't try it (if you do then you will waste soo much time)
(pick random () to (10))
MELP_JV
Scratcher
2 posts

How can I make a sprite bounce off another sprite depending on the direction?

oh my God I almost feel bad for this guy he's got nothing but hate comments
Oh_biscuits_hello2
Scratcher
1 post

How can I make a sprite bounce off another sprite depending on the direction?

me too
deck26
Scratcher
1000+ posts

How can I make a sprite bounce off another sprite depending on the direction?

MELP_JV wrote:

oh my God I almost feel bad for this guy he's got nothing but hate comments
There are several posts offering help so I don't see how you interpret things that way!

Powered by DjangoBB