Search code examples
unity-game-enginepositiontransformitween

How to transform world position to local position in unity 3d for itween


I am struggling in problem that convert world position in local position. i am using iTween plugin in unity. And there is an argument of position in iTween which is take world position and but i want to use local position in pixel to move the object in iTween. I tried with transform.TransformPoint(new Vector3(0,0,0) i don't thing it is working according to pixel position.

like this example:

iTween.MoveTo(gameObject,iTween.Hash("position",new Vector(0,0,0) , "time" ,.6, "easetype" ,"easeincubic"));

the argument of position iTween take in World position but i want to convert in pixel position. Like i pass new Vector(450,50,0);

your help will be appreciated.


Solution

  • You can try to use Camera.current.WorldToScreenPoint(Vector3 vector) which returns a Vector3 with x and y in camera space, meaning between values between 0 and 1.

    By multipling those values with Screen.width or Screen.height would give you the position in pixel.