2D Toolkit Forum

2D Toolkit => Support => Topic started by: Euthyphro on September 24, 2013, 10:16:02 am

Title: C# How to get mouse click location as transform position relative to camera?
Post by: Euthyphro on September 24, 2013, 10:16:02 am
I'm trying to use Input.mousePosition to get mouse click location, however, I can't seem to convert it to the actual position in-game to move an object.

What I'm trying to do is obtain the actual position in game when a mouse is clicked based on a tk2dtilemap and using tk2dcamera. Transform coordinates are based off of the tilemap. I don't want the pixel coordinates based on lower left side of the screen and top right side of the screen, I'm trying to obtain the actual transform position so I can move an object to the point clicked using i.e. Vector3.Lerp(startVector, mouseClickVector, TIme.deltaTime);

I'm not sure of the math or how it works to convert the Input.mousePosition to the actual transform position? Could someone share how they've done this?


Thanks.
Title: Re: C# How to get mouse click location as transform position relative to camera?
Post by: unikronsoftware on September 24, 2013, 11:24:11 am
Convert Input.mousePositiion to a worldPosition using tk2dCamera.Instance.camera.ScreenToWorldPosition(...) - you can then use that world position to move your object, etc.