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

#1 2012-08-06 17:17:50

Thrystor
Scratcher
Registered: 2011-04-10
Posts: 100+

Does anyone know a good way to figure out which way a line is going?

I'm trying to make a game involving lasers and mirrors, and I need to figure out how to make lasers bounce if they're touching a mirror. I'm using a color sensor to detect mirrors. Does anyone know a good way to make the laser bounce off of the mirrors? Or at least to figure out what direction the mirror is pointing without switching off of my color sensor.


http://codersshed.webuda.com/favicon.ico Cool stuff awaits the technically literate...

Offline

 

#2 2012-08-06 17:43:32

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Does anyone know a good way to figure out which way a line is going?

Are you using a pen or stamping to make the laser? That would help me with telling you how to make the laser turn.

Last edited by ErnieParke (2012-08-06 17:45:37)


http://i46.tinypic.com/35ismmc.png

Offline

 

#3 2012-08-06 18:00:54

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Does anyone know a good way to figure out which way a line is going?

When they touch the mirror, this script should cause the light to bounce the correct way:

(This script was taken from the wiki)

when gf clicked
go to x: (0) y: (0)
point in direction (pick random (-179) to (180))
set [Move Speed v] to [0]
forever
move (Move Speed) steps
if <touching [mirror v]?>
change x by (([sin v] of (direction)) * ((0) - (Move Speed)))
if <touching [mirror v]?>
point in direction ((180) - (direction))
else
point in direction ((0) - (direction))
end
change x by (([sin v] of (direction)) * (Move Speed))
end

Last edited by Prestige (2012-08-06 18:02:43)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#4 2012-08-07 07:16:28

Thrystor
Scratcher
Registered: 2011-04-10
Posts: 100+

Re: Does anyone know a good way to figure out which way a line is going?

Prestige wrote:

When they touch the mirror, this script should cause the light to bounce the correct way:

(This script was taken from the wiki)

when gf clicked
go to x: (0) y: (0)
point in direction (pick random (-179) to (180))
set [Move Speed v] to [0]
forever
move (Move Speed) steps
if <touching [mirror v]?>
change x by (([sin v] of (direction)) * ((0) - (Move Speed)))
if <touching [mirror v]?>
point in direction ((180) - (direction))
else
point in direction ((0) - (direction))
end
change x by (([sin v] of (direction)) * (Move Speed))
end

Thanks! This works well! I'll be sure to give credit to you and the wiki. It would be nice if it worked with diagonal mirrors as well as horizontal and vertical, but I guess you can't have everything.


http://codersshed.webuda.com/favicon.ico Cool stuff awaits the technically literate...

Offline

 

#5 2012-08-07 07:17:31

Thrystor
Scratcher
Registered: 2011-04-10
Posts: 100+

Re: Does anyone know a good way to figure out which way a line is going?

ErnieParke wrote:

Are you using a pen or stamping to make the laser? That would help me with telling you how to make the laser turn.

I'm using the pen. Someone else already came up with a script for it though.


http://codersshed.webuda.com/favicon.ico Cool stuff awaits the technically literate...

Offline

 

#6 2012-08-07 07:56:32

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Does anyone know a good way to figure out which way a line is going?

Thrystor wrote:

ErnieParke wrote:

Are you using a pen or stamping to make the laser? That would help me with telling you how to make the laser turn.

I'm using the pen. Someone else already came up with a script for it though.

Okay.


http://i46.tinypic.com/35ismmc.png

Offline

 

#7 2012-08-07 08:21:54

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Does anyone know a good way to figure out which way a line is going?

Thrystor wrote:

Thanks! This works well! I'll be sure to give credit to you and the wiki. It would be nice if it worked with diagonal mirrors as well as horizontal and vertical, but I guess you can't have everything.

Does this not work on diagonals? Have a look at this, it might help you  smile

Last edited by Prestige (2012-08-07 08:26:01)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

Board footer