How to make AI in top-down game?

aamod

  • Posts: 18
I had made an AI which shoots the actor in its LOS.
But it also shoot the actor if there is Wall in front.
I used simple raycasting(shoot the actor if distance is less than 300)
I want AI to stop shooting the actor if wall is coming in middle how can i do it?

Thank.

merrak

  • *
  • Posts: 2016
There's a raycasting extension available in the extensions forum that will let you test for the presence of an object between two points. It uses Box2D, though, so is not an option if you're using simple physics.

A (faster) alternative would be to use a simple vector algebra trick. (obligatory clickbait link: This one vector algebra trick will save you hundreds of CPU cycles!) I mentioned how I used it in this thread and gave another link to an in-depth discussion.

Someone who's new to Stencyl would probably find the extension easier to use, unless they're already starting with a stronger programming background.

Unless you have thousands of actors running checks every frame, either solution should perform well enough to do what you need it to.

aamod

  • Posts: 18
Thanks for the reply.
1. Can i do it only with blocks?(I have no programming knowledge of stencyl but can make complex apps in Visual Studio)
2.How do i can make tiles to raycast(since enemy raycast should be intersect with other raycast(tile's) to detect obstacle)
3.Is it nice idea to make matrix of the whole map?

Thank you.

merrak

  • *
  • Posts: 2016
1. The raycast extension packages everything you need into a couple of blocks. You could implement the alternate approach using a custom block or custom global block that takes the eight coordinates as input. For the actual function you'd just need a bunch of math blocks. My advice would be to use the extension if you want to get your game up and running faster.

2. I haven't used the raycast extension in a long time, so I don't remember the details off the top of my head how to use it. Instructions should be provided, though. Raycasting checks for collisions against any collision shape. One of the blocks will return a list of objects that were between the two points you ran the computation against. You can then loop through them and check what kinds of bodies (actors, tiles, etc.) they were.

3. I don't know what you mean by "matrix of the whole map".