This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-10-28 09:50:52

chrisbown
Scratcher
Registered: 2011-07-29
Posts: 100+

how do you you bounce off walls when you touch them?

it's an auto scrolling platforming game that gets faster as you go on that this needs help with.

Last edited by chrisbown (2012-10-28 10:01:05)


check out this: Tank physicshttp://scratch.mit.edu/projects/hamstercake11/3082288

Offline

 

#2 2012-10-28 09:58:29

awesomeness321
Scratcher
Registered: 2012-08-10
Posts: 100+

Re: how do you you bounce off walls when you touch them?

If the walls are on the edge, you could do

if on edge, bounce
Otherwise, you could do:
forever
if <touching color [#000000]?>//The color of the walls
point in direction ((180)-(direction))
move (1) steps//i don't think this part is needed, but I would use it.

Last edited by awesomeness321 (2012-10-28 09:58:45)


My newest project:http://blocks.scratchr.org/API.php?user=awesomeness321&amp;action=projects&amp;type=newest&amp;return=image&amp;num=1Color:#30F9A5 I am currently http://blocks.scratchr.org/API.php?user=awesomeness321&amp;action=onlineStatus&amp;type=text

Offline

 

#3 2012-10-29 10:16:09

Nekrobat
Scratcher
Registered: 2012-07-17
Posts: 18

Re: how do you you bounce off walls when you touch them?

You can do this,

if on edge, bounce
If its a ground/wall do this,
forever if <<color is touching color>>//1,the side of the player color2, the ground/wall color//
move (-10) steps// to get the player away from the ground/wall
[/scratchblocks

Last edited by Nekrobat (2012-10-29 10:16:42)


http://i46.tinypic.com/14w5d2v.jpg

Offline

 

#4 2012-10-29 18:10:37

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: how do you you bounce off walls when you touch them?

chrisbown wrote:

it's an auto scrolling platforming game that gets faster as you go on that this needs help with.

If the walls are all parallel or perpendicular to the x axis, you can just reverse the x and y velocity (depending on whether you hit a "wall" or a "ceiling".

when gf clicked
forever
figure out changes to x and y velocity
change x by (xvel)
if<touching [wall v]?>
set [xvel v] to ((-1)*(xvel))
change x by (xvel)
end
change y by (yvel)
if<touching [wall v]?>
set [yvel v] to ((-1)*(yvel))
change y by (yvel)
end


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer