- Home /
Question by
vhagharvhaghar · Aug 11, 2015 at 03:34 PM ·
objectdrag
Object moves to camera position when clicked with mouse
I'm having this problem alot lately, each time I try to drag an object with mouse click, the instant I click on the object to drag it, it moves to the camera position, this might be some stupid little issue but its really annoying and I couldnt figure out whats the problem, heres my script and I really dont think Script is the problem : void Update () {
if (Clicked)
{
Drag ();
}
void OnMouseDown()
{
Clicked = true;
}
void OnMouseUp(){
Clicked = false;
}
void Drag()
{
Vector3 MousePose = Camera.main.ScreenToWorldPoint(Input.mousePosition);
MousePose.z = 0f;
this.transform.position = MousePose;
}
The object collider is already check Triggger!
Comment
Answer by Youri1er · Aug 11, 2015 at 03:59 PM
50 is the minimum distance with the camera i think. but i'm pretty sure you don't want to do MousePose.z = 0;
Vector3 MousePose = Camera.main.ScreenToWorldPoint(Input.mousePosition.x,Input.mousePosition.y,50); this.transform.position = MousePose;
Your answer
![](https://koobas.hobune.stream/wayback/20220611235403im_/https://answers.unity.com/themes/thub/images/avi.jpg)