Center a Object at hit.point in Camera
Hi, i have a system to "grab" an object an drag it around. But if i grab it at any point, it jumps at the center position in the camera. i need to know how to grab the object without center the objects center into the camera.
Its hard to explain xD
Answer by hexagonius · Jun 23, 2017 at 09:41 AM
Just save the offset to the center and add it every time you reposition the object due to dragging
Answer by ZoXlike · Jun 23, 2017 at 09:56 AM
Ok, but how can i do this? i have this to move the object around
selectedObject.gameObject.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen));
i can get the Offset with hit.point - hit.collider.gameObject.transform.positon right?
but how can i put this offset into the movement?
Save it on mouse down, add it in in mouse move. Right now this is a one liner. You'd need a step in between to calculate what you correctly assumed.
Your answer
![](https://koobas.hobune.stream/wayback/20220612124737im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make Objects so as they do not leave an area around another object 1 Answer
Start moving unchecks itself 0 Answers
how to make an object change size automatically when playing so it doesnt go through objects 0 Answers
Strange Physics2D.Raycast behaviour 0 Answers
How can i stop the stretch effect of a material when i add it to an object and then resize it 2 Answers