Analog plug, but success is difficult to insert.

Analog plug, but success is difficult to insert.

Want to do a demo, an outlet, a plug, plug a cable connection, I used a wire linked physics, with the mouse and drag it to insert a socket. But it is difficult to operate. Would like to add a supplementary source of strength is as close to plug socket When socket automatically inserted. Who can help me.

There are a few ways you can do this. The simplest way is to have the plug’s position “snap” to the outlet position if it is within a certain distance. For this, you’ll have to specify the target position and orientation:

var targetPosition : Vector3;
var snapDistance : float = 1;

function Update() {
	if (Vector3.Distance(transform.position, targetPosition) < snapDistance) {
		transform.position = targetPosition;
	} else {
		//the dragging code you have already
		//...
	}
}

More complex (but nicer-looking) solutions would build on the above code by adding an attractive force between the plug and the outlet that increases as the distance between the two decreases.

Thank you very much. Happy