Pages: 1
Topic closed
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
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 endIf that doesn't work, try reversing the red and blue colors.
Last edited by HD123 (2012-02-12 15:18:02)
Offline
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 endIf that doesn't work, try reversing the red and blue colors.
If the line is straight then there is an easier way.
Offline
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)
Offline
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
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)
Offline
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?
Offline
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.
Offline
Thanks for the block fixing. (I don't understand how the forum blocks work...)
Offline
how do i get to make your x and y thing?
Offline
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 endthe 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)
Offline
Topic closed
Pages: 1