Search Unity

Problem to get the position of a point in a linerenderer not in worldspace

Discussion in 'Scripting' started by White_Games, Feb 1, 2020.

  1. White_Games

    White_Games

    Joined:
    Feb 19, 2019
    Posts:
    6
    I have drawed a linerenderer which isnt set to world space, but when i try to set the position of a gameobject to the position of a point in the line, it goes to the worldspace point and not the localspace poit.

    How could i change that?
     
    awsapps likes this.
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You should be able to achieve the effect with the following approach:

    1) get the object's transform (the one that's got the line renderer component)
    2) get the point from the line renderer to which you want to move the object
    3) on the transform, use TransformPoint and pass that point
    4) use the return value of TransformPoint as world space coordinates for the object you want to move

    If you want to handle both, local and world space configurations, you can skip 3) for line renderers that are configured for world space.