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

#1 2013-03-24 16:27:58

Censealea
New Scratcher
Registered: 2013-03-05
Posts: 1

How do I make it so sprites can't go through borders?

I mean with out having to go back to another sprite. For example my brother need help for his zombies game and had black borders around but he wanted it so you can't pass through them, I want to know this for other games so please don't just teach me how on to do this on the zombie game  smile

Offline

 

#2 2013-03-24 16:41:01

parent2nj
New Scratcher
Registered: 2012-10-21
Posts: 9

Re: How do I make it so sprites can't go through borders?

Way I did it is for the sprite to check if it's touching color black (border color) then I'd move the sprite back to where it came from.  You can take a look at:  http://scratch.mit.edu/projects/parent2nj/3195343

The tricky part was the sprite could get stuck on the wall.  So, I had to detect if the sides were touching the wall and then move the sprite away.  Take a look at the thread I started entitled "Stuck on wall" for the discussion.

Hope this helps!

Offline

 

#3 2013-03-24 16:45:11

parent2nj
New Scratcher
Registered: 2012-10-21
Posts: 9

Re: How do I make it so sprites can't go through borders?

Oh, take a look at this thread which covers exactly what you need:  http://scratch.mit.edu/forums/viewtopic.php?pid=1141838#p1141838

Offline

 

#4 2013-03-30 02:38:16

shivadas
Scratcher
Registered: 2010-02-06
Posts: 100+

Re: How do I make it so sprites can't go through borders?

Hi there! There are a few ways you can do this. The first is by sensing the border color.

when gf clicked
forever if (touching color [border color] ?)
go to [Start position]
The second is to do it by sensing the border sprite
when gf clicked
forever if (touching [Border v] ?)
go to [Start position]
You could also instead use broadcasts:

when gf clicked
forever if (touching color [border color] ?)
broadcast [Touching Border v]
when gf clicked
forever if (touching [Border v] ?)
broadcast [Touching Border v]
And then tell the moving sprite that when it receives the message it needs to stop the scripts that allow it to move.

Hope that helped!


Please check out my latest project, Hunger Avenger!

Offline

 

#5 2013-03-30 09:50:59

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: How do I make it so sprites can't go through borders?

I made some tutorials for this on my help account! Here ya go: http://scratch.mit.edu/projects/7734f_help/3208892 and http://scratch.mit.edu/projects/7734f_help/3208907


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

Board footer