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

#1 2012-02-12 14:17:05

natashasharan
New Scratcher
Registered: 2012-02-11
Posts: 1

How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

So I use the Drawing_Pencil  sprite to draw a line.  Now I want my car sprite to follow along that line .  How can I do it ?

Offline

 

#2 2012-02-12 14:18:04

gabric
Scratcher
Registered: 2011-07-23
Posts: 100+

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

Is the line straight?


http://mag.racked.eu/cimage/i57.1/Found+a+good+server%21/Welcome+to+CupCake+Craft%21/mca.png

Offline

 

#3 2012-02-12 15:16:44

HD123
Scratcher
Registered: 2009-12-05
Posts: 500+

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

First, have the car go to the start of the line.  Draw a red and a blue sensor on the left and right sides of the car.  Point the car in the starting direction, and then you can use this script:

when i receive [drive v]
forever
move (1) steps
if <color [#0000FF] is touching [#000000]>
repeat until <not <color [#0000FF] is touching [#000000]>>
turn cw (-1) degrees
end
end
if <color [#FF0000] is touching [#000000]>
repeat until <not <color [#FF0000] is touching [#000000]>>
turn cw (1) degrees
end
end
end
If that doesn't work, try reversing the red and blue colors.

Last edited by HD123 (2012-02-12 15:18:02)


~~HD123~~
Treat others as you want to be treated. |  big_smile  | http://i.imgur.com/OaNrY.gif | http://blocks.scratchr.org/libstatus.php?user=HD123&amp;online=http://lemonfanatic.webs.com/ONLINE.png&amp;offline=http://lemonfanatic.webs.com/OFFLINE.png

Offline

 

#4 2012-02-12 18:14:15

gabric
Scratcher
Registered: 2011-07-23
Posts: 100+

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

HD123 wrote:

First, have the car go to the start of the line.  Draw a red and a blue sensor on the left and right sides of the car.  Point the car in the starting direction, and then you can use this script:

when i receive [drive v]
forever
move (1) steps
if <color [#0000FF] is touching [#000000]>
repeat until <not <color [#0000FF] is touching [#000000]>>
turn cw (-1) degrees
end
end
if <color [#FF0000] is touching [#000000]>
repeat until <not <color [#FF0000] is touching [#000000]>>
turn cw (1) degrees
end
end
end
If that doesn't work, try reversing the red and blue colors.

If the line is straight then there is an easier way.


http://mag.racked.eu/cimage/i57.1/Found+a+good+server%21/Welcome+to+CupCake+Craft%21/mca.png

Offline

 

#5 2012-02-12 18:28:52

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

Heres another way. Assume that x1, x2, y1, and y2, are the coordinates of the points in the line.

when flag clicked
set [angle v] to ([atan v] of (((x2) - (x1)) / ((y2) - (y1))))
forever
change x by ([cos v] of (angle))
change y by ([sin v] of (angle))
end

Last edited by bobbybee (2012-02-14 19:27:17)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#6 2012-02-12 21:02:05

landonpants13
New Scratcher
Registered: 2012-02-12
Posts: 2

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

I tried your idea, but it didn't work.  Here is my scratch file:

http://dl.dropbox.com/u/61958901/Robot%20Racecar.sb

Thanks in advance!!
Landon

Offline

 

#7 2012-02-12 23:11:09

CheeseMunchy
Scratcher
Registered: 2008-10-13
Posts: 1000+

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

there's this:

when gf clicked
forever
glide 0.5 seconds(or whatever) to sprite1
or this
when gf clicked
forever
go to x: <[x position] of [sprite1] + 20>  y: [y position] of [sprite1]
Or some other things that will probably be harder.

Last edited by CheeseMunchy (2012-02-12 23:12:59)


6418,

Offline

 

#8 2012-02-12 23:24:37

Luxturna
Scratcher
Registered: 2011-04-24
Posts: 38

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

natashasharan wrote:

So I use the Drawing_Pencil  sprite to draw a line.  Now I want my car sprite to follow along that line .  How can I do it ?

not sure HOW to do it, but can you add a link to the project?


http://scratch.mit.edu/static/icons/buddy/782569_med.png?t=2012-03-10+00%3A38%3A57

Offline

 

#9 2012-02-14 19:15:11

360-International
Scratcher
Registered: 2011-07-17
Posts: 100+

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

bobbybee wrote:

Here's another way. Assume that x1, x2, y1, and y2, are the coordinates of the points in the line.

when flag clicked
set [angle v] to ([atan v] of (((x2) - (x1)) / ((y2) - (y1))))
forever
change x by ([cos v] of (angle))
change y by ([sin v] of (angle))
end

Fixed.


https://lh4.googleusercontent.com/Oib6kyze-OrCFIRlqL6HYnWuHBQp1GfFoh5CkBlZGe3_9WCk-_DDwgfFrnD_mxJ_x2b18hMUyV2KVtIDiLdebyWaQQ6fbpKpZs-8auVep1zoSgOv-iA

Offline

 

#10 2012-02-14 19:26:44

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

Thanks for the block fixing. (I don't understand how the forum blocks work...)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#11 2012-02-18 11:27:19

landonpants13
New Scratcher
Registered: 2012-02-12
Posts: 2

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

how do i get to make your x and y thing?

Offline

 

#12 2012-02-20 12:10:10

PencilFactory
Scratcher
Registered: 2011-11-11
Posts: 100+

Re: How To Follow along on a Line Drawn by Drawing_Pencil Sprite ?

as the drawing pencil is drawing add its position in a list
when the pencil is done drawing set pencil done drawing to 1

when gf clicked
set [pencil done drawing v] to [0]
forever
  add (x position) to [pencil x v]
  add (y position) to [pencil y v]
  if <(pencil done drawing) = [1]>
    stop script
  end
end
the car will go to those positions

when gf clicked
wait [1] secs
set [i v] to [0]
forever if <(pencil done drawing) = [1]>
  repeat (length of [pencil x v])
    change [i v] by [1]
    go to x: (item (i) of [pencil x v]) y: (item (i) of [pencil y v])
  end
end

Last edited by PencilFactory (2012-02-20 12:20:16)


PencilFactory is http://blocks.scratchr.org/API.php?user=PencilFactory&amp;action=onlineStatus&amp;type=text, see my computerhttp://mag.racked.eu/cimage/i9002/Achievement+get%21/Computer+crashed/mca.png

Offline

 

Board footer