Controlling a Handle with Mouse Drag?!

Ive really been pulling my hair out over this one! All i have is a handle which should allow the user to click on then drag up and down, then when released will go back to the default position.

Right now i can click on the handle, then when i move the mouse below this initial point the handle rotates down and vice versa. However how can i have the handle ‘follow’ the mouse position? So that the handle isn’t either ON or OFF, it can be controlled precisely with the mouse?

Thanks for any help :smile:

make and empty object, and place your handle as a child of that object. make sure ur handle is set to start in the midle of the empty object. then rotate the empty object on the x or z axis. the center of the empty object will act as a pivot for your handle.

(I hope i understood your question)

or:

hey ar0nax thanks for your help but thats not really what i am asking (but it is helpful!).

I need to be able to click on the handle and control it with the mouse (rotate it on one axis when i move the mouse up and down on the screen)

Thanks

i’ll try to do something, i’ll post what i managed to do.

so here’s the thing i came up with. you make a invisible plane, then u cast a ray from the cam onto that plane (that plane has a collider), you take the impact point and u make the handle lookat that point.

593522–21122–$New Unity Project 2.rar (85.8 KB)

ar0nax thanks! this is very helpful, however how cud i constrain the rotation to only one axis and prevent it from spinning around?

Thanks for your time

i made the object a rigidbody and checked the contraints not to rotate on z and y, but it doesn’t work… dunno why.

did a little search and this is what i could find:

void Awake() {
        rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY;
    }

Edit: the above does not work, but i found a solution, all you have to do is add this line:
hit.point.x = 0; after this oneDebug.DrawLine (ray.origin, hit.point); in the file mouseclick.js i gave u in the attachement.

ar0nax, thanks for your help… i will give this a try.