Hello Guest

Author Topic: C# How to get mouse click location as transform position relative to camera?  (Read 5206 times)

Euthyphro

  • Newbie
  • *
  • Posts: 20
    • View Profile
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.
« Last Edit: September 24, 2013, 10:18:10 am by Euthyphro »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Convert Input.mousePositiion to a worldPosition using tk2dCamera.Instance.camera.ScreenToWorldPosition(...) - you can then use that world position to move your object, etc.