Field of Vision Mathematics Help

For questions about using Classic.

Post » Tue Mar 02, 2010 4:46 am

Say, I wanted to make a stealth game for a contest and I wanted to clone the way MGS1 handles FOV for enemies.
So basically every enemy has a pie-shaped FOV. When the player crosses that, he blows his cover and will be chased down by enemies.

The problem is how to make that pie shape. If it's 360FOV(basically a circle), it's easy to compute using distance formula, but with a pie(fraction of a circle), I'm not sure how the formula will go. Help?
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Tue Mar 02, 2010 5:07 am

Pie-shaped detector sprite with containers?
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Tue Mar 02, 2010 5:11 am

Just use the line of sight behavior, that has the field of vision (angle range) that you're wanting, and distance it can see.
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Tue Mar 02, 2010 5:21 am

Keep in mind distance(x,y,xx,yy) works off of hotspots, so the distance is basically half the radius of the circular field of vision. So distance() will give you 360 degrees regardless.
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » Tue Mar 02, 2010 8:36 am

You can do this by "drawing" a line to each object within range and checking if it overlaps any solids. If you want a partial visibility, you can draw two lines instead - from the observer to edges of the target's bounding box to form a cone. If one line is obstructed but other is not, the target is partially visible.

Though overlapping and collision tests are CPU intensive. I believe a raytracing plugin would be a better option to reduce the overhead. There is Line of Sight plugin, for one.

If you want to simulate a Field of View effect - an overlay, a flickering torch or whatever - that is another story altogether. You want to draw a polygon that is limited by obstacles, this would be difficult to replicate in Construct.

It would be much easier if you had an "obstacle map" and used a certain pathfinding/flow algorithm to fill the area around player, then use this data to draw the Field of Vision.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Mar 02, 2010 10:00 am

The way I plan to handle obstacles is that after it confirms that the player is withing range, have it check for an 'obstacle' across the line of sight. I will keep it simple and just use the sprite holder(collision box) of the player to be checked and not the actual sprite,and make use of certain stances(stand, crouch,crawl) to be tested against the obstacles and will give a fake partial visibility testing.
I haven't tried the Line of Sight Behavior - I think I should have before posting this - but I like itt to be flexible so I try to make my own functions as possible.
B
16
S
10
G
5
Posts: 255
Reputation: 3,934


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests