unity-game-engineleap-motion

Unity Leap Motion Detecting Finger collision with other fingers/palm


I am new to using Unity and Leap motion.

I have copied over the HandModels and LeapHandController from the Unity Asset Pack Desktop demo.

I am trying to activate a function to instantiate an object when the thumbs bone 3 collides with any other part of the hand and i did this by creating a simple script with an OnCollisionEnter function and attaching it to the Bone3 of Thumb but it doesn't seem to activate when the thumb collides with any other part of the hand/finger that it is a child of. If i add a cube to the scene and give it a rigidbody it will successfully trigger the onCollisionEnter of the thumb (shown via a print statement), but it wont trigger oncollisionEnter with any of its siblings in the hand model.

I am unsure how the standard method for detecting finger collisions with other objects using Leap Motion and Unity is, but it doesn't seem to follow the standard Unity Collision system. Is there another way i should be detecting it? It would be helpful if i could detect collisions of a hands child bones, but right now it seems i have to signal to the hand manually that a child bone has collided.


Solution

  • If you've copied over HandModels from a Desktop demo, the physical hand you're working with is probably a RigidRoundHand -- you can confirm this by checking what objects are underneath your HandModels object.

    If it is indeed the RigidRoundHand, or otherwise using the RigidHand script to generate the colliders of the hand, the issue you're observing comes from the fact that a hand is all one rigidbody, so the reason you aren't seeing OnCollisionEnter is because the rigidbody doesn't receive OnCollisionEnter when it "collides" with itself.

    To accomplish what you're trying to do, instead of relying on the default colliders of the hand, you should place specific Rigidbody + Collider objects (such as the default Unity Cube) on the specific locations of the hand you'd like to detect collision against. I would recommend using the Attachment Hands made available in a recent release to do this: It will make it easy for you to place individual Rigidbodies on specific joints in the hand, such as the tip of the thumb, and the other locations you're trying to collide against.

    Make sure you're using the latest version of the Leap Motion Unity SDK, then check out the example scene in LeapMotion/Core/Examples/Attachment Hands/ in your Assets folder. Make sure you have a Kinematic Rigidbody Collider (a SphereCollider is a good choice) under the Attachment Hand's thumb, and add some script like:

    public class ThumbCollisionDetector : MonoBehaviour {
      void OnCollisionEnter(Collision c) {
        if (c.gameObject.GetComponent<MiddleFingerIdentifier>() != null) {
          Debug.Log("The thumb collided with the middle finger identifier!");
        }
      }
    }
    

    In the above example, we're looking for a "MiddleFingertipIdentifier" script in the collision, so we need to make sure there's an object with a Kinematic Rigidbody and a Collider attached (via Attachment Hands) to the tip bone of the middle finger -- the identifier script doesn't even have to contain anything, it just has to be there:

    public class MiddleFingertipIdentifier : MonoBehaviour { }
    

    That logic should get you started detecting internal hand intersections.