2D click to move character - change coordinates of target position from world to local

Hello everyone!

I have recently started messing around in Unity and currently I’m learning to make a point and click adventure game. I have a character with a click to move movement mechanic that works fine, and a blend tree to show the correct animation when moving in various directions. In my blend tree I have floats of “x” and “y” position of the click point. The problem is, I’d like to convert these coordinates to ones relative to the player, they are currently those of the screen. This means the character shows for example the “walking left” animation only if I click left of the center of the screen. I’ve tried to use InverseTransformPoint, but I couldn’t get that to work.

Could you please give me some advice how to approach this? I am still in the early stages of learning C#, any help will be greatly appreciated.

Thank you in advance :slight_smile:

Outta do it, something like:

var ray = Camera.main.ScreenPointToRay(MousePos);
var worldPoint = ray.origin;
//Compare worldpoint to player pos

Havent tested but that should work, if not may need to get a collision from the ray using Physics.Raycast() then check the impact point.