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

#1 2010-07-17 03:03:47

Gveradux
Scratcher
Registered: 2010-06-18
Posts: 100+

I need a sensor script

I want my sprite not to go through walls or bushes so I put COLOUR SENSING in, but it took me an hour to make. I want a script that will bounce off the script, for e.g.

If touch top of bush
change y by 1

if touch bottom of bush
change y by-1

if touch left of bush
change x by-1

if touch right of bush
change x by 1

Help!! Plz!

Offline

 

#2 2010-07-17 06:56:10

laser100
Scratcher
Registered: 2009-12-04
Posts: 100+

Re: I need a sensor script

bounce off the script?

Offline

 

#3 2010-07-17 06:59:06

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: I need a sensor script

Just make an outline of a slightly different colour around each side of your bush, and use those as colour sensing.

However, that might not works so well if you bush isn't a rectangle. In that case, I can't help you all that well.

By the way, when you change x by -1, you have to make sure it's enough to counteract any opposite motion - are you sure it's enough?

Offline

 

#4 2010-07-17 07:18:34

Gveradux
Scratcher
Registered: 2010-06-18
Posts: 100+

Re: I need a sensor script

Yep, It's in my game EEVEE ROAM and it works fine. Plz play and comment and press love it, pleeassseee! I'll just have to stick too my old script, which is COLOUR SENSING,  sad  oh well...

Offline

 

#5 2010-07-17 09:10:11

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

Re: I need a sensor script

Try looking at this project's script, may or may not help. It uses single color sensing (the wall and the moving sprite are both only one color, so it looks more professional than making every side of a wall a different color. You could also adapt it to using <touching[


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

Offline

 

#6 2010-07-17 10:45:52

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: I need a sensor script

Try making a box with various colored sides to go to the sprite. Give it a ghost effect of 100. Then say (If touching color _ ).


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#7 2010-07-17 11:30:35

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

Re: I need a sensor script

If touching bush...
check direction of player travel (you can use distance too or not) then adjust motion according to that, like a Pong paddle.

To do a round reflection, face bush towards player and use it's direction to set the new player direction (or bounce.)


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

Offline

 

#8 2010-07-17 17:38:34

JeanTheFox
Scratcher
Registered: 2010-06-14
Posts: 1000+

Re: I need a sensor script

Simple solution: Make four sprites that are lines. (Make them stand out from the background) Two of them horizontal, two vertical. Tell them to go to the x and y position in the center of the bush. Now try a little trial-and-error using the change x by: and change y by: block to make your lines on the outsides of your bush. Now make your sprite you want to 'bounce' off the sides bounce if touching one of the lines. Finally, go to the 'walls' and make them set their ghost effect to zero. (forever is optional) Hope this helps.  smile


http://i51.tinypic.com/20gcn5j.png

Offline

 

Board footer