Moving a rigidbody onto exact mouse position using rigidbody.MovePosition?

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

Try calculating a heading and using the rigidbody.AddForce method.

Vector3 heading = (p - transform.position).normalized;
rigidbody.AddForce( heading * someThrustValue * Time.deltaTime);

Sadly I've never tried to do anything with the camera and the mouse just yet, so I could be completely off base.

EDIT:

When you're obejct has reached the desired position, raise the rigidbody's drag value to stop it from moving.

if( transform.position == p )) //I think p is what you are using to determine the point in space you want the object to move too.
{
    rigidbody.drag = 1000;
}

Give that a shot.

EDIT 2: Electric Boogaloo

You've shown that your results do not have the cube staying with the cursor as it moves, but rather it tries its best to keep up with it. Hopefully this code block will fix that with a different method of moving objects.

transform.position = new Vector3(p.x, transform.position.y, p.z);

I believe that will cause your cube to stay precisely with the mouse pointer as it moves around the screen without it flying in the air.