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:
If that doesn't work, try reversing the red and blue colors.when i receivedrive ▼forevermove1stepsifcolor is touchingrepeat untilnotcolor is touchingturn
-1degreesifcolor is touchingrepeat untilnotcolor is touchingturn
1degrees
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:
If that doesn't work, try reversing the red and blue colors.when i receivedrive ▼forevermove1stepsifcolor is touchingrepeat untilnotcolor is touchingturn
-1degreesifcolor is touchingrepeat untilnotcolor is touchingturn
1degrees
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.
whenclicked
setangle ▼toatan ▼of/x2-x1y2-y1foreverchange x bycos ▼ofanglechange y bysin ▼ofangle
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:
Or some other things that will probably be harder.whenclicked
foreverglide 0.5 secondsor whateverto sprite1or thiswhenclicked
forevergo to x:y:x positionofsprite1+ 20y positionofsprite1
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.
whenclicked
setangle ▼toatan ▼of/x2-x1y2-y1foreverchange x bycos ▼ofanglechange y bysin ▼ofangle
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
the car will go to those positionswhenclicked
setpencil done drawing ▼to0foreveraddx positiontopencil x ▼addy positiontopencil y ▼ifpencil done drawing=1stop script
whenclicked
wait1secsseti ▼to0forever ifpencil done drawing=1repeatlength ofpencil x ▼changei ▼by1go to x:itemy:iofpencil x ▼itemiofpencil y ▼
Last edited by PencilFactory (2012-02-20 12:20:16)
Offline
Topic closed
Pages: 1