Discuss Scratch
- Discussion Forums
 - » Help with Scripts
 - » How to make an AI chase u while moving around walls.
        
         
- UserSam
 - 
                            
						
						
                            Scratcher
                        
						
						 
50 posts
How to make an AI chase u while moving around walls.
I am making a game where there's a enemy trying to kill you. I made walls to create rooms and made a small layout to see if everything works. How do I make the enemy to chase me but not trying to start walking into the wall and be stuck or glitch through and instead to follow the closest path to me.
Here is the horrible start project
https://scratch.mit.edu/projects/446971091
                        
                        
                    Here is the horrible start project
https://scratch.mit.edu/projects/446971091
- thelion5000
 - 
                            
						
						
                            Scratcher
                        
						
						 
100+ posts
How to make an AI chase u while moving around walls.
first, what you would have to do is to turn the walls into sprites, or characters that you can code and delete the walls from the background, you can keep the walls from the background until you can put the walls in the exact place. then you can start adding scripts to the walls. other than that, i can't fix that
                        
                            Last edited by thelion5000 (Nov. 11, 2020 13:58:13)
- UserSam
 - 
                            
						
						
                            Scratcher
                        
						
						 
50 posts
How to make an AI chase u while moving around walls.
first, what you would have to do is to turn the walls into sprites, or characters that you can code and delete the walls from the background, you can keep the walls from the background until you can put the walls in the exact place. then you can start adding scripts to the walls. other than that, i can't fix thatWhat code should I write? Like this
when green flag clicked
set [walls] to [0]
forever
if <touching [ walls] ?> then
move (-10) steps
change [ walls] by (1)
if <(walls) = [ 5]> then
turn cw (20) degrees
move (10) steps
set [ walls] to [0]
end
end
end
Last edited by UserSam (Nov. 12, 2020 00:51:13)
- UserSam
 - 
                            
						
						
                            Scratcher
                        
						
						 
50 posts
How to make an AI chase u while moving around walls.
Here is the horrible start projectOk this link is now invalid.
https://scratch.mit.edu/projects/446971091
- gltchr
 - 
                            
						
						
                            Scratcher
                        
						
						 
6 posts
How to make an AI chase u while moving around walls.
How do I make the enemy to chase me but not trying to start walking into the wall and be stuck or glitch through and instead to follow the closest path to me.
I think you should learn something called pathfinding. I'm not sure how to do it in scratch. You can use algorithms like A*, but this will require a lot of variables. You could make a list of cells with coordinates and data of all cells that you can go from current cell. Then you will search throught the list to find the path.
This may help: https://en.scratch-wiki.info/wiki/Pathfinding
Last edited by gltchr (Nov. 19, 2020 12:41:22)
- UserSam
 - 
                            
						
						
                            Scratcher
                        
						
						 
50 posts
How to make an AI chase u while moving around walls.
How do I make the enemy to chase me but not trying to start walking into the wall and be stuck or glitch through and instead to follow the closest path to me.
I think you should learn something called pathfinding. I'm not sure how to do it in scratch. You can use algorithms like A*, but this will require a lot of variables. You could make a list of cells with coordinates and data of all cells that you can go from current cell. Then you will search throught the list to find the path.
This may help: https://en.scratch-wiki.info/wiki/Pathfinding
I know I can make a path finder but how do I incorporate into an enemy as most path finders are grids and blocks?
- GunChleoc
 - 
                            
						
						
                            Scratcher
                        
						
						 
500+ posts
How to make an AI chase u while moving around walls.
The enemy needs to knw which block it is in and which block you are in, then use the blocks from the pathfinder to decide wich block to go to next.
                        
                        
                    - UserSam
 - 
                            
						
						
                            Scratcher
                        
						
						 
50 posts
How to make an AI chase u while moving around walls.
The enemy needs to knw which block it is in and which block you are in, then use the blocks from the pathfinder to decide wich block to go to next.@GunChleoc
I know I have to do that but i am not that good as I just joined a month ago. If possible could you help me with the code. She is a demo link https://scratch.mit.edu/projects/450318838
- gltchr
 - 
                            
						
						
                            Scratcher
                        
						
						 
6 posts
How to make an AI chase u while moving around walls.
demo link https://scratch.mit.edu/projects/450318838Can you add some in code comments? I'm not sure what are some lines doing. Also which sprite is used for pathfinding?
btw If the map would be static, you could do some points on the map instead of cells on the grid. Then you could insert data from which points you can go to other points in straight line. It would be less data to store. In this case you should use A* because it uses different travel costs(in this case distances between points).
Last edited by gltchr (Nov. 16, 2020 11:49:42)
- Discussion Forums
 - » Help with Scripts
 - 
            » How to make an AI chase u while moving around walls. 
         
            


