Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Does anyone know how I can program AI that you might be familiar with?
- -R4x-
-
Scratcher
100+ posts
Does anyone know how I can program AI that you might be familiar with?
Here’s a scuffed example of the ai made even worse due to the disability of being a mobile player
Purple = can’t go
Blue = can go but isn’t good way to reach target
Green = chosen direction
https://i.postimg.cc/JnFk1Qfp/ezgif-com-gif-maker-3.gif
When a enemy lands in a new tile (so if the custom block starts) it choses 4 tile around them to turn to, it can never go backward unless it’s private variable “State” gets changed (unless if it changes from or to “4”), then it’s forced to turn 180 degrees no matter what. Anyways, they can’t backwards and they can’t go into anything named “Level” like
Whichever tile is closest to the target (which name is in a variable named “target”) gets chosen. If multiple tiles are chosen it does a priory depending on which direction it’s facing, the priory is Up, Left, Down, Right (Facing Up having the highest priority, Down the lowest level). If you can’t understand something please tell me
Purple = can’t go
Blue = can go but isn’t good way to reach target
Green = chosen direction
https://i.postimg.cc/JnFk1Qfp/ezgif-com-gif-maker-3.gif
When a enemy lands in a new tile (so if the custom block starts) it choses 4 tile around them to turn to, it can never go backward unless it’s private variable “State” gets changed (unless if it changes from or to “4”), then it’s forced to turn 180 degrees no matter what. Anyways, they can’t backwards and they can’t go into anything named “Level” like
(join [Level] [])So I can test different stuff and won’t have to keep change the blocks.
Whichever tile is closest to the target (which name is in a variable named “target”) gets chosen. If multiple tiles are chosen it does a priory depending on which direction it’s facing, the priory is Up, Left, Down, Right (Facing Up having the highest priority, Down the lowest level). If you can’t understand something please tell me
Last edited by -R4x- (Dec. 13, 2022 17:55:28)
- huboojoe
-
Scratcher
100+ posts
Does anyone know how I can program AI that you might be familiar with?
a link to the game could be great
- MijiGamin1_is_cool
-
Scratcher
100+ posts
Does anyone know how I can program AI that you might be familiar with?
You could prob do sum like
ofc this is just an example, but this is what i would do
when I receive [move v]
set [direction random v] to (pick random (1) to (10))
if <(direction random) > [5]> then
move up
end
if <<[4] < (direction random)> and <[8] > (direction random)>> then
move left
end
if <(direction random) = [10]> then
move down
else
move right
end
ofc this is just an example, but this is what i would do
Last edited by MijiGamin1_is_cool (Dec. 8, 2022 14:45:58)
- -R4x-
-
Scratcher
100+ posts
Does anyone know how I can program AI that you might be familiar with?
You could prob do sum likewhen I receive [move v]
set [direction random v] to (pick random (1) to (10))
if <(direction random) > [5]> then
move up
end
if <<[4] < (direction random)> and <[8] > (direction random)>> then
move left
end
if <(direction random) = [10]> then
move down
else
move right
end
ofc this is just an example, but this is what i would do
Wouldn’t this make the enemy go in random directions
- ProfessorUelf
-
Scratcher
100+ posts
Does anyone know how I can program AI that you might be familiar with?
Here’s a scuffed example of the ai made even worse due to the disability of being a mobile playerHello @-R4x-,
Purple = can’t go
Blue = can go but isn’t good way to reach target
Green = chosen direction
https://i.postimg.cc/JnFk1Qfp/ezgif-com-gif-maker-3.gif
When a enemy lands in a new tile (so if the custom block starts) it choses 4 tile around them to turn to, it can never go backward unless it’s private variable “State” gets changed (unless if it changes from or to “4”), then it’s forced to turn 180 degrees no matter what. Anyways, they can’t backwards and they can’t go into anything named “Level” like(join [Level] [])So I can test different stuff and won’t have to keep change the blocks.
Whichever tile is closest to the target (which name is in a variable named “target”) gets chosen. If multiple tiles are chosen it does a priory depending on which direction it’s facing, the priory is Up, Left, Down, Right (Facing Up having the highest priority, Down the lowest level). If you can’t understand something please tell me
from what I've understood, you are looking for a “shortest path algorithm with movement costs”.
I recently discovered a very good website that explains the basics of pathfinding algorithms in an interactive way.
Unfortunally it's written in Python, so you'll have to transfer it into scratch.
https://www.redblobgames.com/pathfinding/a-star/introduction.html
If you scroll down to the chapter “Movement Costs”, you'll get a pretty good overview of how to approach the issue.
Hope this helps.
Edit: Nvm, I think I understood it the wrong way. You're probably just searching for a standard pathfinding algorithm.
Last edited by ProfessorUelf (Dec. 13, 2022 21:30:09)
- Discussion Forums
- » Help with Scripts
-
» Does anyone know how I can program AI that you might be familiar with?