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

1

Index

Stats

10,105 visits, 21,392 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 16 Nov, 2012. Last updated 19 Feb, 2019

C2 Turret Behavior Supersedes this

When I wrote this tutorial, there was no turret behavior in C2. It exists now, so may be the functionality of the behavior is much better than this. Try turret behavior. :)

Please Note:

I didn't make this tutorial too detailed on assumption that you are well acquainted with scirra basics like spawning an object or picking instances. Wherever, you face difficulty understanding, please search the same line on Scirra forum and you should be able to get how it is done.

Apology for that, not much time on hands to do a full detailed tutorial.

Just spent a freaking full caffeine filled night to get this to work.

Tutorial:

Hey all,

I've been writing this top down tank game prototype and one of the major issues I faced is to let the enemy units decide when to start firing.

So this tutorial is to share how it was achieved.

State of Game before reading further:

1. You have enemy units placed and your window size is smaller than your Layout size.

2. You have let enemy turn to player position and shoot every 1 sec or 5 secs.

Problems:

1. Enemy units keep shooting at you from all directions whether you see them within your window size or not.

2. Enemy units keep spawning un-necessary bullets that hit some solid in between you and enemy if you are not in line of sight.

What was tried, but didn't work according to expectations:

I tried this Line of sight example,

- but to tie a UID to every line of sight seemed restrictive

- it doesnt address the range of enemy fire issue

- didn't work properly with multiple instances of same enemy types

- the for each loop consumes more computing resources specially if you dont want all enemies to fire at once (especially if there are five enemies who have line of sight.. you're fscked :D )

But that example did help a bit in part of how I formed the solution.

Thanks @dcrew for that :)

What are we going to achieve:

1. Enemies should have a range / radius within with if player closes in, they decide to shoot

2. Enemies should not un-necessarily shoot if the player is behind a wall or tree

  • 0 Comments

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