#Map charting system

1 messages · Page 1 of 1 (latest)

waxen shale
#

I have a diver. The diver will have a navigation device that will chart out his movements.

I was thinking of saving the vector3 of the diver every x distance moved, then draw a line renderer line between the points in successive order.

Since it will be diagetic on a screen carried by the player, it will need to be converted into 2d, so that x and z will be shown. I was thinking of changing the color of the lines between the points to indicate altitude changes.

Anyway, not sure how to do this. I don't think a render texture is the right way.

Probably just mathematically but I'm not sure how to move it then when player moves. Not sure how to actually do it, even though I probably understand how it should work.

safe hollow
#

What exactly are you struggling with? Converting the world points to screen points for the navigator? Or choosing how to render it? It's a bit vague what part you need help with.

#

I can think of a few ways of rendering it
-Separate camera renders linerenderers and map image onto rendertexture - simplest, not sure how it will perform tho
-Compute shader draws the lines into a rendertexture and you just overlay that with the map texture
-World-space linerenderer directly on the screen - might look OK or weird, depends on your game's style

waxen shale
#

As for rendering, not sure if I can do line renderers on a canvas. Maybe I do it without the canvas and make actual line renderers with points being manually positioned on the screen, idk

#

I'd also have to be able to change color of the lines between points, just not sure how to go about it

waxen shale
#
public class Map : MonoBehaviour
{ 
    List <Vector3> MapPoints = new List<Vector3>();
    Vector3 lastPoint;
    float distanceThreshold = 1.5f;
    float mapScale = 0.02f;
    float yMultiplier = 0.001f;
    public LineRenderer line;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        if (MapPoints.Count == 0)
        {
            AddPoint();
        }
    }

    // Update is called once per frame
    void Update()
    {
        float distanceSquared = (transform.position - lastPoint).sqrMagnitude;

        if (distanceSquared > distanceThreshold )
        {
            AddPoint();
        }

        for (int i = 0; i < MapPoints.Count; i++)
        {
            Vector3 localPosition = GetLocalPosition(MapPoints[i]);
            // Vector3 drawPoint = transform.TransformPoint(localPosition);
            // Debug.DrawRay(drawPoint, transform.up, color: Color.yellow);
            line.SetPosition(i, localPosition);
        }
    }
    void AddPoint()
    {
        Vector3 currentLocation = transform.position;
        MapPoints.Add(currentLocation);
        lastPoint = currentLocation;
        Debug.Log("Map Points = " + MapPoints.Count);
        //Debug.Log(lastPoint);
        line.positionCount = MapPoints.Count;
    }

    Vector3 GetLocalPosition(Vector3 worldPoint)
    {
        Vector3 offset = worldPoint - transform.position;
        return new Vector3(offset.x * mapScale, 0.001f * (offset.y * yMultiplier), offset.z * mapScale);
    }
}

lusty canopy
#

the 0.001f in GetLocalPosition shouldn't be there probably

#

not an issue, just a comment on quality

waxen shale
#

I am already using the yMultiplier variable

#

oh well, we will never know

#

but there seems to be no issue here, right?

lusty canopy
waxen shale