- Home /
Mouse Position returns wired values with Cinemachine2D
Hello everyone. I am having wired behavior with Cinemachine2D.
I have following code in my Update() Loop:
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log(Input.mousePosition);
}
}
I am using Cinemachine2D and on start it does follow a GameObject and it works just fine. The values look good. (Bottom left of the screen shows (0.4, 6.0, 0.0) for example)
Once I change the Following Target (another Game-Object at the same Position as the previous Object) it suddenly shows totally different values (-2897.9, -1014.0, 0.0) also on the left bottom corner.
Of course that messes up all my ray casts to see if one objects has been touched...
Can anyone explain me why and how I can solve the problem, because I need to change the following target dynamically?
Thank you very much and best regards, Luke
Are you sure you’re clicking within the game window? (0,0) to (Screen.width, Screen.height) is within the game window. If you are getting negative readings, you are likely outside of the game window:
https://docs.unity3d.com/ScriptReference/Input-mousePosition.html
Answer by SomehowLuke · Dec 08, 2020 at 11:31 PM
Hi, thanks for the hint but Iam absolutely sure, that I do click (almost) at the same spot. But definitely not 3000 units away. But I found out, if I add the follow object by code it works. Problems happen if I use the unity editor hirarchy and drag and drop. Therefore I do not have a problem, because in the final game it will be added by code. Just wanted to test it by hand but something seems to go wrong that way.
Copy, but Input.mousePosition is returning screen space, not world space, so it is not in units, but in pixels.