Topic: Use LineRenderer to draw route

Hey,
For few days, I'm using the drawing API to draw route on my tileset map (use on a raw image, UI). Without any route, my app running up to 900 fps. At the moment I use the drawing api, I drop to 20-50 fps. So i searched on the forum and i found that LineRenderer could be a solution. So I searched for some example, and I didn't found what I was searching for.

Using this code :

LineRenderer lineRenderer = map.AddComponent<LineRenderer>();
lineRenderer.sharedMaterial = lineRendererMaterial;
lineRenderer.useWorldSpace = true;
lineRenderer.widthCurve = AnimationCurve.Constant(0, 1, 2);
lineRenderer.startColor = lineRenderer.endColor = Color.blue;
lineRenderer.positionCount = coords.Count;

      
for(int i = 0; i< coords.Count; i++)
{
    Vector3 p = OnlineMapsTileSetControl.instance.GetScreenPosition(coords[i].x, coords[i].y);
    lineRenderer.SetPosition(i, new Vector3(p.x, 2, p.y));
}               

PunBB bbcode map

The violet lineRenderer is not at the right position and not in the right direction (inverse).
if I set the new Vector3 to : 

lineRenderer.SetPosition(i, new Vector3(-p.x, 2, -p.y)); 

The route has the correct direction, but not the right position.

Can you help me please ? sad If you can make an script example, with just 2 positions (2 vector2 with Lon et La) for the line renderer and draw it at the right place and direction on the tileset map, I would be very happy big_smile

Thanks, have a good day/night

Re: Use LineRenderer to draw route

Hello.

The problem is that you use GetScreenPosition.
In your case, you need to use GetWorldPosition:
http://infinity-code.com/doxygen/online … 6316068362

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Use LineRenderer to draw route

Hi,
Thank you very much !
For those who are interest :

void Start()
{
     UpdatePoints();

    OnlineMaps.instance.OnChangeZoom += OnChangeZoomOrPosition;
    OnlineMaps.instance.OnChangePosition += OnChangeZoomOrPosition;
    OnlineMapsTileSetControl.instance.OnMeshUpdated += OnMeshUpdated;
}

private void UpdatePoints()
{
    lineRenderer.positionCount = coords.Count;

    for (int i = 0; i < coords.Count; i++)
    {
         Vector3 p = OnlineMapsTileSetControl.instance.GetWorldPosition(coords[i].x, coords[i].y);
         lineRenderer.SetPosition(i, new Vector3(p.x, p.y, p.z));
    }
         needUpdatePoints = false;           
 }

private void OnMeshUpdated()
{
    if (!needUpdatePoints) return;
    UpdatePoints();
}

private void OnChangeZoomOrPosition()
{
    needUpdatePoints = true;
}

Re: Use LineRenderer to draw route

hi, Pouki can u please send whole script, as some part of this script might be missing , nd it causing errors ,it will be really helpful for me ,thank you