Discuss Scratch

legohero8
Scratcher
9 posts

If on edge, bounce... but not on the edge.

Hi! I need help, I need to know how to do “If on edge, bounce” but not on the edge. I am making walls that could be put inside of the game, and they could be like edges. The link to the game I'm talking about is here: https://scratch.mit.edu/projects/498869027
I have a piece of code on my main character that looks like this:
when green flag clicked
forever
if on edge, bounce
end
Now that is grouped up with all the moving code too, so don't get confused about that.
I need to know how to do that, and it doesn't matter how I do it. I could paint my backdrop to have black lines, I could have a sprite called “Walls”, or anything else like that.
I just need to know how to do it.


Note: This is my first post! Wooooo!

https://u.cubeupload.com/AquaCodes/legohero8.gif
deck26
Scratcher
1000+ posts

If on edge, bounce... but not on the edge.

So you need to detect touching the wall (or whatever) and change direction when you do so. The correct angle for a normal bounce depends on the angle of the object and the angle of approach - see https://scratch.mit.edu/projects/99412537/
legohero8
Scratcher
9 posts

If on edge, bounce... but not on the edge.

Thanks! I can now make my game, but I still got some more code to do also.
Also, don't worry, I'll give credit. I always give credit

https://u.cubeupload.com/AquaCodes/legohero8.gif

Powered by DjangoBB