Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Path finding in a maze
- 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!
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
Thanks however my maze is much more complex and I wanted something to chase the player around, between walls. 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!
- BigNate469
- Scratcher
1000+ posts
Path finding in a maze
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.Thanks however my maze is much more complex and I wanted something to chase the player around, between walls. 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!
Highlight any part of this signature and press ctrl+shift+down arrow to see the rest of it
foreverPlease read the list of Officially Rejected Suggestions before posting a suggestion for Scratch! 100th post
if <person asks [what's a signature] :: sensing> then
Redirect to [https://en.scratch-wiki.info/wiki/Signature] :: motion
end
end
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 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
[color=color name or hexadecimal value here] and [/color]
Lesser-known Scratch URLs:
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)
View a larger list at: https://scratch.mit.edu/discuss/topic/542480/
Why @Paddle2See's responses are so often identical: https://scratch.mit.edu/discuss/topic/762351/
1000th post
- Nickbeeu2
- Scratcher
4 posts
Path finding in a maze
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.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.Thanks however my maze is much more complex and I wanted something to chase the player around, between walls. 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!
- Discussion Forums
- » Help with Scripts
- » Path finding in a maze