I have a gameobject that can be moved in a 3D space. Depending on where the model was clicked (basically, the hit.point of a RaycastHit), I want it to move along with the mouse.
So I can get the model to move to the position based on its own pivot point
But I want to then adjust for the position on the part of the model that was hit by the ray, so the hit.point is over the PositionToMoveTo, instead of just the gameObjects pivot. How would I adjust its position?
![alt text] : /storage/temp/5579-example1.jpg
The red dot is the position that was clicked. The green position is where the objects pivot is (so its transform.position).
![alt text] : /storage/temp/5580-ex.png
Wherever the mouse is, the red dot should be right underneath. The model does not rotate with the camera, but the position should move with the mouse. The green dot (the position/pivot of the model), should not be underneath the mouse. But with the code above, that is what it currently is.
I figure what you want, is to be able to click on the head of the humanoid, and then move the mouse, and the head will stay stuck to the mouse cursor position. You also have to state what kind of plane you want the humanoid to move in, in the formulas, because the mouse cursor can decide 2 dimensions and not depth. You said it doesn't matter the camera angle, so for the moment we can use the plane facing the camera for the plane or horizontal compared to the humanoid.
1st of all, you have to determine the point clicked, compared to the object position, and make it a variable.
modelpointclicked = world hit position - hit GameObject position;
You should also become familiar with different mouse clicking options, because the one you selecting works at exactly 5 metres:
Raycast.point will give you the point of collision of model at any distance
so then, you have mesh point click which should be something like 1 m 70 above the humanoid transform position, and so you are going to use hitGameObjectposition + modelpointclicked as the point that will follow your mouse cursor.
also you can trick the mouse cursor follow script to provide a following point 1 m 70 under the actual visible mouse position.
I'm not even sure how to make something follow the mouse cursor! I would have to look it up, but I hope that helps.