0
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ Have you considered simply hiding Hand, and performing all the interactions you need with HandClone? \$\endgroup\$ – DMGregory Jan 22 at 2:46
  • \$\begingroup\$ 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. \$\endgroup\$ – nightfarrow Jan 22 at 2:49
  • \$\begingroup\$ Hint: Anything Leap can do to a mesh, you can do to your own mesh, including replicating the finger movements. \$\endgroup\$ – DMGregory Jan 22 at 2:50
  • \$\begingroup\$ 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. \$\endgroup\$ – DMGregory Jan 23 at 13:43
0
\$\begingroup\$

Constraining one gameobject within another is easy - add a collider to it. Or in your case if you have two hands, simply reset the position of the second original object to be the same as the second object - the one with the colliders.

However, your problem sounds a bit more related to Leap Motion and its design best practices, and not general unity. For that it seems that Leap Motion have a ready asset called RigidHand, which should deal with all the physics for you.

\$\endgroup\$
4
  • \$\begingroup\$ This is frustrating... RigidHand still clips through things. d2qnpzub7vnpid.cloudfront.net/original/3X/1/6/… I feel very at a loss. Can you expand on the first solution you mentioned? HandClone needs to copy LeapHand's movements but actually stop when colliding with a rigidbody with frozen constraints. LeapHand (and HandClone presently) keep just clipping through constrained rigidbodies. \$\endgroup\$ – nightfarrow Jan 22 at 23:16
  • \$\begingroup\$ In your FixedUpdate you move the HandClone to be positioned where the original hand is - using physics. Immediately after doing that, you can try to reposition the original hand based on the results of this physics-based movement. It may conflict with the hand controller's movement system though. \$\endgroup\$ – tbkn23 Jan 23 at 8:09
  • \$\begingroup\$ 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. \$\endgroup\$ – nightfarrow Jan 23 at 9:14
  • \$\begingroup\$ This probably happens as I feared due to conflict between Leap Motion's own controller (which moves the hand to the position of your physical hand based on the leap motion's input), and your own script changing it's position (based on the physical-based hand-clone). These each move the object to different positions which cause the stuttering, if I have to guess. At this point I would suggest contacting Leap Motion's own support and try to get the RigidHand to work, that's what it's meant for after all. \$\endgroup\$ – tbkn23 Jan 23 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.