I want to show an object at the mouse position. But the object is moving relatively to the mouse but in a shifted position. I’m using
transform.position = Input.mousePosition;
I want to show the object exactly at mouse position.
I want to show an object at the mouse position. But the object is moving relatively to the mouse but in a shifted position. I’m using
transform.position = Input.mousePosition;
I want to show the object exactly at mouse position.
Hi!
Input.mousePosition is calculated in pixels (The same way you would use the old GUI). I suggest doing something like:
transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if this does not work i suggest trying to raycast. You can probably look around on google for a bit and find something about this.
//Proximal Pyro
Input.mousePosition will give you numbers that are 1 per pixel for screen width and screen height (like 1280 x 720).
It has nothing to do with a transform.position which is 1 per unit in your world scene.
As @bubzy mentioned if it’s a 3d game you will want to do a Unity - Scripting API: Camera.ScreenPointToRay
If it’s 2d you can get away with a cheaper: