Discuss Scratch

fnsdspns
Scratcher
5 posts

starting problems with a breakout game

Hi all,

just started scratch so a lot of stuff to learn…

one of the things i encountered in my script/sprite creating a breakout game :

depending on the direction a rectangular sprite is touched by the ball, it has to react in another way : if it touches horizontal, it has to change direction like direction * -1, if it touches vertical, it has to change direction to 180 degrees minus direction.

How can i let the sprite detect how it is being touched ?

my firts thoughts : creating 2 “shadow” sprites, one with the horizontal edges and one with the vertical edges and always use the 3 sprites together and programming the 2 “shadow” sprites on their correct behaviour, but is this the best way or are there better ways to deal with this problem ?

(i hope i explained the problem clear enough to understand )

thanx in advance…
weegaweek
Scratcher
100+ posts

starting problems with a breakout game

you can calculate the angle between to sprites, or you can use the “point towards” block and take the direction.

simpe solution:
pointtowardsballdirection

trigonmetry solution:
atanofyposition-y positionofball/xposition-x positionofball

the benifit of the trigonometry solution is that the sprite may maintain its current direction, which i think is neccesary for your project

Last edited by weegaweek (Jan. 12, 2020 22:24:47)

fnsdspns
Scratcher
5 posts

starting problems with a breakout game

thanks for the help ; now i just have to figure out which directions are corresponding with what side of the rectangular.

Powered by DjangoBB