0
\$\begingroup\$

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.

2018-01-07_7-45-55

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();
    }

}

image

\$\endgroup\$
  • 1
    \$\begingroup\$ I think D:OS and D:OS2 have a grid-based system (from my experience playing both games). They check whether your character can see those grids and "light them up", but this doesn't necessarily mean that you can hit anywhere that is not grayed out. It just means that you can see it and can target it somewhere within that grid tile. \$\endgroup\$ – John Hamilton Jan 8 '18 at 6:14
  • \$\begingroup\$ To add to John comment. They probably don't just create mesh because it would be too performance heavy. Instead they could create a texture and have visual shader that grey-scales this area. Actually like fog of war, it's the same (it is fog of war). To lead you to the right path on creating fog of war - you would probably want a small texture something like 256 x 256 created and then scale it up to something like 1024, or 2048 and blur it out. - I guess it was this way, League of Legends has blog-post where they explain how they do fog of war. \$\endgroup\$ – Candid Moon _Max_ Mar 13 '18 at 9:28
0
\$\begingroup\$

I believe you want to extrude the mesh at each vertex by moving it out by the normal * some fixed scalar. (This leads to some issues around edges)

Here is a more detailed explanation: How do I generate a 3D race track from a spline?

and https://stackoverflow.com/questions/3039026/edges-on-polygon-outlines-not-always-correct/3058978#3058978 for corners

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.