Pinning Objects Together

Hello

I am trying to pin multiple objects together (and keep them attached)

What I would like to do is click on one object, grab that raycasthit.point, click the second object and pin the first tansform to that. Ive got it kind-of working with the code below.

But i see some problems,

  1. How can i account for rotations (my 3d math is weak)
  2. How can i keep them pinned (would a hinge joint be good for this?)
#pragma strict

private var tmpPoint: Vector3;
private var tmpTransform : Transform;

function Update () {
   if (Input.GetMouseButtonDown(0)) {
    var ray = camera.ScreenPointToRay(Input.mousePosition);
 	var hit : RaycastHit;
      	if (Physics.Raycast(ray, hit, Mathf.Infinity)) {
			if(tmpTransform==null) {
				tmpTransform = hit.transform;
				tmpPoint = hit.point;
			} else {
				tmpTransform.position = tmpTransform.position+(hit.point-tmpPoint);
			}
		}
	}
}

Hi,

can you elaborate on:

if you are only changing the position of the object then its rotation should stay unchanged, no?
Or are you trying to change the position and rotation?
for the second question, you could also make the objects children of another game object to keep them moving, rotating together. (when performing operations on the parent)

Both objects have the potential to be moving and rotating and some animated.

I just tried parenting them, and it worked beautifully!
My thinking got way too complicated :stuck_out_tongue:

Thanks

When we tried doing this with the physics (hinge) we had a noticeable delay, particularly for fast animations. parenting solved this problem for us (but you lose the possibility of having the thing fall off based on physics.)

Im using animation’s made in unity and parenting them, they stay pinned while the animation is playing, and then if you turn the animation off it falls off rather nicely