# How to restrict movement of Leap Motion hand object

I have a "Hand" GameObject controlled by a Leap Motion Controller. The Hand despite having RigidBody and Box Collider just seemingly moves with no regards to physics (transform translate movement I suppose). So it clips through other Rigidbody objects.

I'm trying to pseudo-introduce physics to it. I created a second GameObject "HandClone" (with Rigidbody and Box Collider) that copies the first Hand position but moves with actual physics. HandClone script:

   private void FixedUpdate()
{
rb.MovePosition(targetTransform.position);
rb.MoveRotation(targetTransform.rotation);
}


Now HandClone goes where Hand goes, and HandClone is successfully bumping into other objects.

However, when HandClone gets stopped by something, Hand still keeps moving past HandClone and clips into the other objects, like before.

Now I am thinking that the way to solve this is to constrict Hand's movements to the bounds of HandClone so that finally Hand will stop clipping through objects. But how can this be achieved, would that even work, and is there a better way? Will movement streamed from Leap Motion Controller even respond to scripts like that?

__

Edit: I've now decided to hide Hand and place HandClone where Hand was.

But my script for HandClone to copy Hand's movements is making HandClone fly all over the place. Here's the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class clone1 : MonoBehaviour
{
private Rigidbody rb;
public GameObject target;
void Start()
{
rb = this.GetComponent<Rigidbody>();
}

// Update is called once per frame
void Update()
{

}
private void FixedUpdate()
{
Vector3 newRotation = new Vector3(target.transform.eulerAngles.x + 8.5f, target.transform.eulerAngles.y - 172.78f, target.transform.eulerAngles.z - 94.02f);
rb.MoveRotation(Quaternion.Euler(newRotation));
}
}


The reason why I am adding those float numbers is because when the game isn't playing, those numbers are what make HandClone sit in the correct position, so I thought it would help with alignment in playmode. But HandClone is just flying everywhere regardless. Any advice with making the HandClone stay attached to the avatar's wrist would help.

• Have you considered simply hiding Hand, and performing all the interactions you need with HandClone? – DMGregory Jan 22 at 2:46
• I would need to think over how to do that without losing all the intricate finger movements and such. Maybe replacing just the palm if possible. Thanks, I'll think on this. – nightfarrow Jan 22 at 2:49
• Hint: Anything Leap can do to a mesh, you can do to your own mesh, including replicating the finger movements. – DMGregory Jan 22 at 2:50
• It's generally not safe to add two sets of Euler angles together and expect to get their composition. Euler angles behave very non-uniformly. You might want to make a quaternion out of your desired orientation offset, and compose the quaternions instead. – DMGregory Jan 23 at 13:43

• Thank you. I'm trying to figure out how to get HandClone to move where the original hand is, using physics. For some reason, having a script on HandClone that uses MovePosition to the original GameObject's transform.position and transform.rotation, causes the 'HandClone' GameObject to rapidly stutter/blink around, even though it is not colliding with any rigidbodies, rather than smoothly go where the original Hands are. If I do AddForce instead of MovePosition it moves smoothly but I've yet to figure out how to use AddForce to make it perfectly copy another object's position&rotation. – nightfarrow Jan 23 at 9:14