hariavm
September 10, 2014, 7:26am
1
i am using the below script,it s working fine.but i want to know y we must calculating distance and y mot using input.mouseposition.z,???
i am confused help me
if (Input.GetMouseButtonDown(0)) {
float distance = transform.position.z - Camera.main.transform.position.z;
targetPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
targetPos = Camera.main.ScreenToWorldPoint(targetPos);
}
transform.position = Vector3.MoveTowards (transform.position, targetPos, speed * Time.deltaTime);
}
Dantus
September 10, 2014, 8:40am
2
Please use code tags whenever you show code:
If you see someone who needs to know about code tags, please link them to this post: Please use code tags when posting code. You can "tag" your code by typing around your code. There is no overt "Code" tag button that automatically tags a...
Reading time: 9 mins đź•‘
Likes: 83 ❤
The mouse position only contains x and y coordinates, which is just the position of you mouse on the screen. Not more, not less. Everything else needs to be computed. You can use a method as described or use raycasting or even something else.
In general it doesn’t even make sense to provide a z coordinate, because it would just be misleading and confusing.
hariavm
September 10, 2014, 8:49am
3
Thanks for ur reply.
what is the use of screenpointtoworldpoint?
Dantus
September 10, 2014, 8:55am
4
It translates screen coordinates to world coordinates…
hariavm
September 10, 2014, 11:04am
5
what is mean by screen coordinates? and world coordinates?
Dantus
September 10, 2014, 11:42am
6
Screen space is defined in pixels. The bottom-left of the screen is (0,0); the right-top is (pixelWidth ,pixelHeight ).
World space is an actual 3d position.