The car is controlled by two sprites. Each which look like identical cars except for a single dot, for one sprite in front and to the left of the car, and for the other in front and to the right.
The cars always move forwards, so if the car with dot on the left is touching the border colour outside the track, then it's the dot that's touching the colour and the car needs to turn right, so it sets it's variable "turndirection" to 2. If it's not touching the colour outside the track, it set's "turndirection to 0".
If the car with dot on the right is touching the border colour outside the track, then the car needs to turn left, so it sets it's variable "turndirection" to -2, otherwise it is set to 0.
The variable turndirection is local to each car (to make sure one script doesn't override the other).
The left-dot car sets the position for both cars. Within a loop, until the race is over, it moves forward according to it's speed variable (starting with a value of about 4), and turns according to the script ;
turn ((turndirection) + ( "turndirection" of s[Cmp1SenseR])) degrees
when I receive [NextRace] set (turndirection) to [0] show repeat (until (RaceOver) = [1]) set (Speed) to ( (Speed) of [Cmp1SenseL] ) if (((touching color c[00CE42]?) and (((turndirection) of [Cmp1SenseL v] ) =[0])) and ((turncnt) < [360])) set (turndirection) to ((Speed) * [-2]) change (turncnt) by [1] else change (turncnt) by -[1] set (turndirection) to [0] End point in direction ( (direction) of [Cmp1SenseL v] ) set (x) to ( (x position) of [Cmp1SenseL v] ) set (y) to ( (y position) of [Cmp1SenseL v] ) End hide end
Offline
AddInnovation wrote:
The car is controlled by two sprites. Each which look like identical cars except for a single dot, for one sprite in front and to the left of the car, and for the other in front and to the right.
The cars always move forwards, so if the car with dot on the left is touching the border colour outside the track, then it's the dot that's touching the colour and the car needs to turn right, so it sets it's variable "turndirection" to 2. If it's not touching the colour outside the track, it set's "turndirection to 0".
If the car with dot on the right is touching the border colour outside the track, then the car needs to turn left, so it sets it's variable "turndirection" to -2, otherwise it is set to 0.
The variable turndirection is local to each car (to make sure one script doesn't override the other).
The left-dot car sets the position for both cars. Within a loop, until the race is over, it moves forward according to it's speed variable (starting with a value of about 4), and turns according to the script ;turn cw ((turndirection) + ( [turndirection v] of [Cmp1SenseR v])) degreeswhen I receive [NextRace v] set [turndirection v] to [0] show repeat until <(RaceOver) = [1]> set [Speed v] to ( [Speed v] of [Cmp1SenseL v] ) if <<<touching color [00CE42]?> and <([turndirection v] of [Cmp1SenseL v] ) =[0]>> and <(turncnt) < [360]>> set [turndirection v] to ((Speed) * [-2]) change [turncnt v] by [1] else change [turncnt v] by [-1] set [turndirection v] to [0] End point in direction ( [direction v] of [Cmp1SenseL v] ) set x to ( [x position v] of [Cmp1SenseL v] ) set y to ( [y position v] of [Cmp1SenseL v] ) End hide end
Script Fixed
Offline
Impressive script. It works, right? You should upload a project using it. I'd be interested.
EDIT: I think you have already, have you?
Last edited by PhirripSyrrip (2012-07-21 11:33:08)
Offline