More "Controllable" Controls

I have a simple controller where you move the mouse around an object and it follows it, in order to make things less complicated (collision detection), I’m using a rigid body to move the object, however the result of using this setup is that I get a “tugging” effect as if the mouse is pulling the object around. Instead I want it to be more “controllable”. My articulation of the problem probably isn’t that good so I posted the script and a link to a web player to better show what I’m talking about.

Controller Script

var speed = 2;

function Update () {

	var mousePos = Input.mousePosition;
	var movePosition : Vector3;
		
	movePosition = Camera.main.ScreenToWorldPoint (Vector3 (mousePos.x, mousePos.y, 1));
		
	var moveDir = movePosition - transform.position;
	
	Debug.DrawRay (transform.position, moveDir);
	rigidbody.AddForce (moveDir * speed);

}

Webplayer Link: https://dl.dropbox.com/u/88635652/Controllable%20Controls/Controllable%20Controls.html

Hi there,
I believe, since I can’t test it right now, that you have to multiply the “moveDir” by the distance between the object and the “mousePosition” and not by “speed”… also if you plan moving objects with a mass more than one, I suggest multiplying by that aswell

Benprodutions1

You clearly need more “drag” on your rigidbody. You just apply a “gravity” force, so it will orbiting around your mouse forever. Increase the drag value on your rigidbody and also increase your speed since the drag will decreases the velocity continuously. You have to play around with the values until you get your desired “feeling”.

edit

Another way would be to not use Addforce and just move the rigidbody to the target location with a smooth damping. This could be done by setting the velocity directly to the target-vector divided by 10 for example.

var moveDir = movePosition - transform.position;
rigidbody.velocity = movedir / 10;

This should be done in FixedUpdate or it will behave different at different framerates. Same for AddForce btw.