Discuss Scratch

Nickbeeu2
Scratcher
4 posts

Path finding in a maze

Could you make an ai to path find a moving sprite in a maze?
20140069G
Scratcher
22 posts

Path finding in a maze

I myself am not a really experienced coder, but here's a project that i saw that might help you!

https://scratch.mit.edu/projects/723209398/

Hope it helps!

Last edited by 20140069G (March 27, 2024 14:55:20)

Nickbeeu2
Scratcher
4 posts

Path finding in a maze

20140069G wrote:

I myself am not a really experienced coder, but here's a project that i saw that might help you!

https://scratch.mit.edu/projects/723209398/

Hope it helps!
Thanks however my maze is much more complex and I wanted something to chase the player around, between walls.
BigNate469
Scratcher
500+ posts

Path finding in a maze

Nickbeeu2 wrote:

20140069G wrote:

I myself am not a really experienced coder, but here's a project that i saw that might help you!

https://scratch.mit.edu/projects/723209398/

Hope it helps!
Thanks however my maze is much more complex and I wanted something to chase the player around, between walls.
This is actually a common enough problem in programming that you can just search “computer pathfinding” and get a load of results. However, the most commonly used algorithm I know of starts at the target (whatever you are trying to move to) and places a square there. This square has a value of 0. It then, on the edges of that square, creates 4 more squares, each with a value of one. If any of the “one” squares are touching a wall, they delete themselves. The one squares then place 4 more squares on their edges, each labeled “2”. If any of the “2” squares are touching a wall or are on top of another square, they delete themselves. This process repeats until a square hits the thing that is trying to move toward the target, upon which the entire process stops. The thing trying to move toward the target then only has to go from the highest numbered square to the lowest numbered square.

Highlight any part of this signature and press ctrl+shift+down arrow to see the rest of it
forever
if <person asks [what's a signature] :: sensing> then
Redirect to [https://en.scratch-wiki.info/wiki/Signature] :: motion
end
end
Please read the list of Officially Rejected Suggestions before posting a suggestion for Scratch! 100th post
This signature is designed to be as helpful as possible.
View all of the topics you've posted in:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=topics
View all of your posts:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=posts
Forum tips:
Don't title topics something like “HELP ME!!!”. It's not helpful, and won't get you as many responses.
Don't post in topics where the latest post is over ~2 months old, unless you have something critical to add. Especially in topics that are several years old- it isn't helpful, and is known as necroposting.
Don't post unrelated things in topics, including questions of your own. Make a new topic for your questions.
You can use the
 [code] and [/code] 
tags to show other users how to format something that Scratch would otherwise format.
You can use the
 [color=color name or hexadecimal value here] and [/color] 
tags to color text.
Little-known Scratch URLs:
scratch.pizza (redirects to main page)
https://scratch.mit.edu/projects/PROJECT ID HERE/remixtree (replace “PROJECT ID HERE” with project id number. Shows all the remixes of the project, and the remixes of those projects, and the remixes of those projects, and so on, as a chart. Link currently redirects to one of my projects)
Nickbeeu2
Scratcher
4 posts

Path finding in a maze

BigNate469 wrote:

Nickbeeu2 wrote:

20140069G wrote:

I myself am not a really experienced coder, but here's a project that i saw that might help you!

https://scratch.mit.edu/projects/723209398/

Hope it helps!
Thanks however my maze is much more complex and I wanted something to chase the player around, between walls.
This is actually a common enough problem in programming that you can just search “computer pathfinding” and get a load of results. However, the most commonly used algorithm I know of starts at the target (whatever you are trying to move to) and places a square there. This square has a value of 0. It then, on the edges of that square, creates 4 more squares, each with a value of one. If any of the “one” squares are touching a wall, they delete themselves. The one squares then place 4 more squares on their edges, each labeled “2”. If any of the “2” squares are touching a wall or are on top of another square, they delete themselves. This process repeats until a square hits the thing that is trying to move toward the target, upon which the entire process stops. The thing trying to move toward the target then only has to go from the highest numbered square to the lowest numbered square.
I tried that and it “worked” but i had to keep recreating the squares since the player is gonna be (probably) constantly moving around which means it would have to recreate all the squares again which lags the project out for a second.

Powered by DjangoBB