Hello there,
my situation: I get the mouse position in 3D space while dragging the object, and it should move to this position. The script works very well so far, but the rigidbody object don't move to the exact mouse position. It recognises the mouse position, and flies to that direction... and it won't stop continue flying around, unless we release the mouse button.
And the important part of my drag script:
function FixedUpdate ()
{
if (dragging == true)
{
rigidbody.isKinematic = false;
var p: Vector3;
var mainCamera = FindCamera();
// Position on the near clipping plane of the camera in world space
p = mainCamera.ScreenToWorldPoint(Vector3
(Input.mousePosition.x, Input.mousePosition.y, mainCamera.nearClipPlane ));
// Position relative to the eye-point of the camera
p -= mainCamera.transform.position;
//[...] ...further distance calculation not necessary here... [...]
//finally, p holds the mouse position
//rigidbody.position = p;
var collisionMoveFactor = 0.1;
p = p.normalized*collisionMoveFactor;
//the questionable part of this script:
rigidbody.MovePosition(rigidbody.position + p);
// only move in its x,z coordinates, rememberedYPos = 1
rigidbody.position.y = rememberedYPos;
}
}
So, I think the mouse position will always be added to the object position... How to avoid this, and only move it to the mouse position?
Edit For the complete script see my other question