0 Replies - 3503 Views - Last Post: 18 February 2013 - 02:22 AM

#1 JaJa1313   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-February 13

Questions about 2D Field of view

Posted 18 February 2013 - 02:22 AM

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?


Is This A Good Question/Topic? 0
  • +

Page 1 of 1