Divinity: Original Sin 2 has an amazing range-of-attack display. When I select a character's abilities, the range of the ability will appear (as shown in the screenshot below).
I'd like to know how to create an effect like this.
You can see this system in motion via this YouTube video
I think It just displayed navmesh , so I tried to display my navmesh.I used NavMesh.CalculateTriangulation()
, GL API
to displaying.
After baking navmesh attach this script to your camera and give this a material:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.AI;
using UnityEngine;
public class NavmeshDebuger: MonoBehaviour {
public Material material;
void OnPostRender() {
var triangulation = NavMesh.CalculateTriangulation();
if (material == null) {
return;
}
GL.PushMatrix();
material.SetPass(0);
GL.Begin(GL.TRIANGLES);
for (int i = 0; i < triangulation.indices.Length; i += 3) {
var triangleIndex = i / 3;
var i1 = triangulation.indices[i];
var i2 = triangulation.indices[i + 1];
var i3 = triangulation.indices[i + 2];
var p1 = triangulation.vertices[i1];
var p2 = triangulation.vertices[i2];
var p3 = triangulation.vertices[i3];
var areaIndex = triangulation.areas[triangleIndex];
Color color;
switch (areaIndex) {
case 0:
color = Color.red; break;
case 1:
color = Color.green; break;
default:
color = Color.blue; break;
}
GL.Color(color);
GL.Vertex(p1);
GL.Vertex(p2);
GL.Vertex(p3);
}
GL.End();
GL.PopMatrix();
}
}