The system explained
So lets go over the system starting at the EQS (project link at bottom).
We use the circle trace which basically traces outwards from midpoint.
From top to bottom following arrows:
Radius is view range.
Space between is the space between trace points, lowering this will make the mesh more accurate around geometry but more expensive.
Arc direction should be checked and set to two points. Line from is querier and line to is a custom contex for the look direction, I’l go over that in a sec.
Arc angle is viewcone size.
Ignore Any Context Actor is very important, without it the trace will hit the querier and will never leave midpoint.
Trace mode should be geometry, otherwise you use the navmesh and that’s just not accurate.
Line works best for trace shape.
The EQS context for forward vector.
The context just gets the forward facing vector of your actor, get this in whatever way works best. My actor does not turn, it just appears to turn. That is why I don’t use Get Forward Vector.
Now for the generation logic, il also post the actual project. Its well commented (Mostly for myself to remember :))
So the procedural mesh function needs 2 arrays, vertices and triangles. The vertices are just the hit points of the trace (in local space).
First we resize both arrays to the correct size. to do this we get the length of the sector (or circumference if 360) and divide it by spacing between EQS points. Then plus one, don’t know why but it works. This is now the vertex array length, the triangle one is this multiply by 3.
Next populate the triangle array(integers), this is on Event begin play. It looks like this
2 triangle 1
3 triangle 2
4 triangle 3
Each integer is a reference to a vertex, 0 being the center and then the edge ones. One very important thing to remember is that if the view cone is 360 the last triangle needs to connect to vertex 1, otherwise the triangle tries to connect to a non-existent vertex. This is a simple branch that replaces the last triangle vertex.
For people that don’t catch the triangle thing(I know I didn’t till last night) here’s a wonderful illustration.
Red dots are vertices, numbers are references in triangle array.
Green lines are, well, the triangles.
Next the vertices, this is in Event tick(not the best, should rather use a more controlled fast tick, but it works for now).
Literally just translate trace points to local space(sight points on image is the trace points).
After that just plug in the two arrays into the Draw Mesh Section function, the procedural mesh component itself is on the character. The material used has Tow Sided enabled that it is visible.
Project link: https://drive.google.com/open?id=0B1_mL6EWhs3yT0xzZnN3Ty16Ykk
The project also contains some camera movement stuff and cross hair stuff, also a rudimentary AI. Feel free to use all of it.