Enemy AI for Range of Fire and Line of Sight - Top Down player

  • 44 favourites

Index

Stats

5,758 visits, 13,474 views

Translations

This tutorial hasn't been translated.

Tools

4. Run the Layout:

- You should see weird lines being pointed towards player all the way from enemy every 3.0 secs

- Enemy far away from 'range' doesn't bother to do it

- Enemy doesn't shoot if player is behind a Wall or Tree

- As soon as you move into a new enemy territory/range.. it starts rotating towards you and shooting.

5. Now we dont want those weird lines cluttering our game do we :)

- Once you confirm that it works, set 'lineofsight' to invisible to make the screen/game cleaner.

How can you extend/improve this:

1. 'Range' can also be set to diagonal width or height or some hard number depending on your requirement or depending on whether you want some enemies to have longer range.

2. Remove pick nearest enemy from step3, if you want all enemy units within 'range' to consider shooting.

3. This tutorial just dealt with 'shooting', but you can add another action and make the enemy 'move' towards the player too.

Please feel free to poke me if something looks troublesome in this tutorial.

Humble note to other Game Devs:

It is only because people have been generous writing other tutorials on scirra (without worrying about Oh! my precious game and tricks of trade) .. is how I learned bits and pieces and improving/changing them seems to solve a lot of stuff in my game... so please give back to the community... do consider writing tutorials. :)

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!