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

#1 2008-04-15 21:59:25

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

How do I make a sprite hit the side of an object and not go through?

Basically, I'd like a character to be able to hit the side of an object but not go through. I've seen projects which do this but I really don't understand them.

Offline

 

#2 2008-04-15 22:07:14

hamimiami
Scratcher
Registered: 2008-04-15
Posts: 6

Re: How do I make a sprite hit the side of an object and not go through?

Here's a simple example.  The sprite balls bounce off of each other and the walls.
http://scratch.mit.edu/projects/hamimiami/142491

Basically within the script for a Sprite you check to see if it is touching another sprite.
If it is touching then you either change the direction of the sprite or stop the movement of it so it doesn't pass through the other one.

Ask if you have any questions.

Offline

 

#3 2008-04-15 22:07:30

Jman720
Scratcher
Registered: 2007-11-27
Posts: 1000+

Re: How do I make a sprite hit the side of an object and not go through?

Try:

<when green flag clicked>
><if><<  <not>touching Sprite 1  >><<  <and>right arrow  >>
<move(10 )steps>


Solve for x
2+3+2+(-9)+1x+2x=7

Offline

 

#4 2008-04-16 16:06:08

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

Re: How do I make a sprite hit the side of an object and not go through?

But is it possible so that it may hit a particular side and bounce off, except the top. For example, if it hits the bottom, can it not go through, and if it hits the right, can it not go through?

Offline

 

#5 2008-04-16 16:43:12

47fg74
Scratcher
Registered: 2007-10-30
Posts: 100+

Re: How do I make a sprite hit the side of an object and not go through?

maybe
<when green flag clicked>
<forever if><touching color[ whatever the thing it not supposed to touch color
<move( -10 )steps>


What emo means....
E is for emontional ruins everbodies day
M is for misrable people
O is for on the dark side... cause we have some fresh cookies

Offline

 

Board footer