|
Hi, I have a very simple scene that contains a cube. I want to be able to drag the cube around with the mouse, in a way that syncs perfectly with the mouse. The mouse cursor should always remain over the object, and visually, the object should move as much as the mouse did. Here's the code I have now:
This works fine when I put the camera in Orthographic mode. So I'm guesing the problem is the perspective isn't taken into account. I should have my cube move more when it is far, and move less when it is close, so that its always in sync with the mouse, but I don't know how to do it. Thank you.
(comments are locked)
|
|
the third argument of ScreenToWorldPoint is the distance between camera and the cube. also in last line you can set the
i have a code that i am sure that it works This made the trick, thanx. temp.z = cube.transform.position.z- mainCamera.transform.position.z;
May 17 '10 at 07:01 PM
didibus
yes it's the trick. as the documentation says z argument should be the distance from the camera but i don't know why people don't read it well. i myself had problem realizing it for some hours. i set this to 0 and my code did not work. i read the docs again and said oops :)
May 18 '10 at 05:03 AM
Ashkan_gc
is there a way to make the mouse follow the object ?
Nov 05 '11 at 02:10 PM
Babilinski
Thanks very much for this! :)
Oct 28 '12 at 11:34 PM
tonydincau
(comments are locked)
|
|
this does not work please make an new question or comment and not an answer
Mar 21 at 10:38 AM
sdgd
(comments are locked)
|
