Hey how can i make one AI sprite go round a map in random directions without getting stuck?
Offline
What about this:
Here is an example maze:
The Blue box is the object that should move around, the red dot is a sensor. It will be made invisable with the "Set Ghost-Effect to 100"-Block. Both objects move on a raster, the sensor is always one step ahead. Btw, one square is 20 x 20. So the sensor-position depends on the position of the Blue box AND on its direction. Here's how the sensor must move:
Yeah, actually the blue box should move to After every step, it broadcasts "Check" and waits. (Waiting is important!!)
when gf clicked forever move [20] steps broadcast [check v] and wait THE OTHER PART OF THIS SCRIPT IS AT THE BOTTOM IT MUST BE RIGHT HERE IN THIS LOOPWhen the sensor receivs "Check", it checks if it's touching the color of the wall in front of the blue box. Therefor, it goes to the square in front of the blue box:
when I receive [check v] if <([direction v] of [Blue Box]) = [90]> set x to (([x Position v] of [Blue Box]) + [20]) set y to ([y Position v] of [Blue Box]) end if <([direction v] of [Blue Box]) = [-90]> set x to (([x Position v] of [Blue Box]) - [20]) set y to ([y Position v] of [Blue Box]) end if <([direction v] of [Blue Box]) = [0]> set x to ([x Position v] of [Blue Box]) set y to (([y Position v] of [Blue Box]) + [20]) end if <([direction v] of [Blue Box]) = [180]> set x to ([x Position v] of [Blue Box]) set y to (([y Position v] of [Blue Box]) - [20]) endIf it does not touch the wall-color (black in this example), it does nothing and this script ends. Then the Blue Box is allowed to make it's next step.
if <touching color [#000000]?> set [Turn? v] to [Yes] delete [All] from [Possible directions v] set x to (([x Position v] of [Blue Box]) + [20]) set y to ([y Position v] of [Blue Box]) if <not <touching color [#000000]?>> add [90] to [Possible directions v] end set x to (([x Position v] of [Blue Box]) - [20]) set y to ([y Position v] of [Blue Box]) if <not <touching color [#000000]?>> add [-90] to [Possible directions v] end set x to ([x Position v] of [Blue Box]) set y to (([y Position v] of [Blue Box]) + [20]) if <not <touching color [#000000]?>> add [0] to [Possible directions v] end set x to ([x Position v] of [Blue Box]) set y to (([y Position v] of [Blue Box]) - [20]) if <not <touching color [#000000]?>> add [180] to [Possible directions v] end else set [Turn? v] to [No] //Of course, if it doesnt' touch black at the beginning, it sets turn to no. endYou remember that the Blue Box who received has been waiting? Well, now that the script is done, it stops waiting and checks, if Turn? = Yes. If so, it goes to one of the POSSIBLE DIRECTIONS. So it chooses a random item form the list "Possible directions" and then the whole loop runs again
if <(Turn?) = [Yes]> point in direction (item [any] of [Possible Directions v]) wait [ ... ] secs // The longer it waits, the slower it moves and the easier is the game.Wow, this is a lot^^ I really hope you use these scripts
Offline
xJira wrote:
What about this:
Here is an example maze:
http://oi48.tinypic.com/1zv9a8y.jpg
The Blue box is the object that should move around, the red dot is a sensor. It will be made invisable with the "Set Ghost-Effect to 100"-Block. Both objects move on a raster, the sensor is always one step ahead. Btw, one square is 20 x 20. So the sensor-position depends on the position of the Blue box AND on its direction. Here's how the sensor must move:
http://oi50.tinypic.com/2q16kr4.jpg
Yeah, actually the blue box should move toAfter every step, it broadcasts "Check" and waits. (Waiting is important!!)
when gf clicked forever move (20) steps broadcast [check v] and wait THE OTHER PART OF THIS SCRIPT IS AT THE BOTTOM IT MUST BE RIGHT HERE IN THIS LOOPWhen the sensor receivs "Check", it checks if it's touching the color of the wall in front of the blue box. Therefor, it goes to the square in front of the blue box:when I receive [check v] if <([direction v] of [Blue Box v]) = [90]> set x to (([x Position v] of [Blue Box v]) + (20)) set y to ([y Position v] of [Blue Box v]) end if <([direction v] of [Blue Box v]) = [-90]> set x to (([x Position v] of [Blue Box v]) - (20)) set y to ([y Position v] of [Blue Box v]) end if <([direction v] of [Blue Box v]) = [0]> set x to ([x Position v] of [Blue Box v]) set y to (([y Position v] of [Blue Box v]) + (20)) end if <([direction v] of [Blue Box v]) = [180]> set x to ([x Position v] of [Blue Box v]) set y to (([y Position v] of [Blue Box v]) - (20)) endIf it does not touch the wall-color (black in this example), it does nothing and this script ends. Then the Blue Box is allowed to make it's next step.
This it what the sensor should do, if it touches a wall (because the bluebox has to change it's direction then): First, you need the variable "Turn?". If the sensor touches the wall-colour it sets "Turn?" to yes. Then, the sensor checks in which direction the blue box might walk next. Therefore, it checks the the four squares next to the blue box.
http://oi45.tinypic.com/2gsizow.jpg
If they aren't black, the Blue Box could walk there next. So we need the List "Possible Directions". First, the sensor delets all of the list. If it does not touch the wall, it adds the possible Direction to the List. In this example, this would be 90 (right) and 180 (down).
So we continue the script like this:if <touching color [#000000]?> set [Turn? v] to [Yes] delete (All v) from [Possible directions v] set x to (([x Position v] of [Blue Box]) + [20]) set y to ([y Position v] of [Blue Box]) if <not <touching color [#000000]?>> add [90] to [Possible directions v] end set x to (([x Position v] of [Blue Box]) - [20]) set y to ([y Position v] of [Blue Box]) if <not <touching color [#000000]?>> add [-90] to [Possible directions v] end set x to ([x Position v] of [Blue Box]) set y to (([y Position v] of [Blue Box]) + [20]) if <not <touching color [#000000]?>> add [0] to [Possible directions v] end set x to ([x Position v] of [Blue Box]) set y to (([y Position v] of [Blue Box]) - [20]) if <not <touching color [#000000]?>> add [180] to [Possible directions v] end else set [Turn? v] to [No] //Of course, if it doesnt' touch black at the beginning, it sets turn to no. endYou remember that the Blue Box who received has been waiting? Well, now that the script is done, it stops waiting and checks, if Turn? = Yes. If so, it goes to one of the POSSIBLE DIRECTIONS. So it chooses a random item form the list "Possible directions" and then the whole loop runs again
if <(Turn?) = [Yes]> point in direction (item (any v) of [Possible Directions v]) wait ( ... ) secs // The longer it waits, the slower it moves and the easier is the game.Wow, this is a lot^^ I really hope you use these scriptsI haven't checked this, but I'm pretty sure it will work.
I hope I explained this well and my english is OK! If there are questions, just ask.
xJira
Fixed your scripts
Offline
ENOUGH with complicated scripts what about "if touching colour XXX move 10 spaces XXX"
this would mean you need different coloured wall but it MIGHT just MIGHT work....
sorry if I'm no help...
Offline
Jem12 wrote:
ENOUGH with complicated scripts what about "if touching colour XXX move 10 spaces XXX"
this would mean you need different coloured wall but it MIGHT just MIGHT work....
sorry if I'm no help...![]()
It's always best to have more complicated but better scripts.
Offline