I am coding a top down 2D game where units have a limited field of view (think Commandos). I've had a look at a view tutorials and forums and I think I've got an idea of what to do, but I still have some gaps I'd like to fill.
Firstly this page helped me with the basic vision.
I use the dot product between where my player is facing and the vector to between the enemy unit and my player to determine if the enemy is in my players view cone. Easy enough, but what about obstacles in the line of sight.
I then looked at this page.
And here is where I need your help:
As I understand it,
Store all corners( Vector2s) in the map in a list.
Determine all corners that are in the view cone.
Scan in a clockwise direction and draw a triangle primitive between two consecutive corners and the player position.
If enemy is in one of the drawn primitives, the enemy is visible.
I already see a problem in that that a corner on a far side of a box or obstacle will also be in my list and it shouldn't. Any ideas on how to remove it/identify it?
Page 1 of 1
0 Replies - 3363 Views - Last Post: 18 February 2013 - 02:22 AM
Page 1 of 1