Finding a local position matching a global position in an individually rotated hierarchy

I know this is a “classic” question, but I still cannot get my head around it.

[139419-skærmbillede-2019-06-04-kl-095954.png|139419]

I have boiled my question down to the attached illustration, and would greatly appreciate if someone can help.
For the sake of Google, other people who should search this, here are some keywords:
I want to find the local position matching a global position in an individually rotated hierarchy .

Your question is quite abstract. However just to find the world space position for a local space position in a given local space, all you need is TransformPoint.

However if you just want to know the world space position of a nested object, just read it’s position property which does this conversion automatically.

edit

I just realised you want to opposite ^^. In this case you want to use InverseTransformPoint or again if you just want to know the local space position of an object within its parent space, read localPosition

second edit

Ahh I think you worded your question in a very confusing way. From your strange line of code I think you actually want to project the other objects position onto the patrolling line. If the patrolling line is always the z axis of the parent space of your evil guy, yes using InverseTransformPoint of that parent object passing the position of the player and then reading the z component would work.

Note your code examples are barely visible due to contrast. When you provide code examples, please include the code in your question and don’t post screen shots / snippets of code.

ill post it as an answer since i think you are talking about something like this

 if (evilGuy.position.y < other.position.y) evilGuy.position += evilGuy.up * speed * time.deltaTime;
 else if(evilGuy.position.y > other.position.y) evilGuy.position -= evilGuy.up  * speed * time.deltaTime;