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

#1 2012-01-11 18:06:39

Hemoxyte
New Scratcher
Registered: 2012-01-11
Posts: 1

Someone help me!

Is it possible to make a sprite get blocked by a block? as in lets say i draw a yellow square, and i want to script it so that the sprite cant move anywhere into the yellow square, I've tried and tried but it just won't work, either the sprite will just move in to and then float up or down. Sort of like mario where you can't go inside the terrain and instead get blocked. Thank you.

Offline

 

#2 2012-01-12 21:52:33

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: Someone help me!

It seems like this would require sensing; this project should be able to explain how to do this (under the sensing tab).  smile

Offline

 

#3 2012-01-13 07:23:21

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

Re: Someone help me!

Yes, but there isn't a single block like "if touching sprite[] bounce".  As laptop97 said above, it requires sensing and building your own collision script.  Depending on what exactly you want to accomplish, such scripts can vary immensely.  Platform scripts tend to be complex than top-down collision scripts, and scripts with velocity tend to be more complex than those without.

Anyway, I can't really answer until I know more details, sorry.  But the basic concept is:

Loop:
   Move
   Check if you're touching the sprite
   If you are, move  back.
End Loop


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

Offline

 

#4 2012-02-01 17:24:11

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Someone help me!

sounds like a good case for sensing to me too but if you want to do your own edge-type bouncing off of an object, here are the 2 formulas for figuring the bounce (depending on whether you hit the sides or top/bottom of an object...
Pong type bounce

this is probably only a partial answer to your question but one of these formulas often confuses us Scratchers so... bam! there it is!!  smile


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

Board footer