0

I created a project that uses data from MediaPipe via a UDP source to capture points of the palm of the hand and finally create a procedural mesh to create a palm surface. This surface is meant to interact with objects in the scene, but even though I added a collider, to the mesh, it does not interact with the objects. I found multiple threads regarding colliders and meshes, but none have solved my problem. Does it have to do with baking it?

See code below:

using UnityEngine;

[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer), typeof(MeshCollider))]
public class ProceduralPalm : MonoBehaviour
{
    public UDPReceive udpReceive;
    Mesh mesh;
    MeshCollider collide;
    Vector3[] vertices;
    int[] triangles;
    public HandTracking handTracking;

void Start()
{
    mesh = new Mesh();
    GetComponent<MeshFilter>().mesh = mesh;
    collide = GetComponent<MeshCollider>();
    collide.sharedMesh = null;
    collide.sharedMesh = mesh;
    mesh.RecalculateBounds();
    CreateShape();
    UpdateMesh();
}

// Creates shape from vectors provided by the UDP Data Stream
void CreateShape()
{
    vertices = new Vector3[]
    {
        new Vector3 (handTracking.x17, handTracking.y17, handTracking.z17),
        new Vector3 (handTracking.x13, handTracking.y13, handTracking.z13),
        new Vector3 (handTracking.x0,  handTracking.y0,  handTracking.z0),
        new Vector3 (handTracking.x1,  handTracking.y1,  handTracking.z1),
        new Vector3 (handTracking.x2,  handTracking.y2,  handTracking.z2),
        new Vector3 (handTracking.x9,  handTracking.y9,  handTracking.z9),
        new Vector3 (handTracking.x5,  handTracking.y5,  handTracking.z5)
    };

    triangles = new int[]
    {
        0, 1, 2, 2, 1, 3, 3, 1, 4,  4, 1, 5, 4, 5, 6,
        //Reverse side of Normals begins here
        2, 1, 0, 3, 1, 2, 4, 1, 3, 5, 1, 4, 6, 5, 4
    };
}

void UpdateMesh()
{
    mesh.Clear();
    mesh.vertices = vertices;
    mesh.triangles = triangles;
}

void Update()
{
    CreateShape();
    UpdateMesh();
}

}

enter image description here

enter image description hereenter image description here

1 Answers1

0

One of the two objects that collide with each other should have a rigid body component. Also, make sure OnTrigger is enabled for the box colliders.

If none of this works please share in more detail what exactly you're trying to achieve.

Vlad

  • both the cube and red sphere have rigid bodies, no issues with those. If I enable OnTrigger on either item it will simple go through the plane. What I want is for the procedural mesh to interact with either sphere or cube object, that is why I am wondering why the Meshcollider doesn't work, in my head it should react with the objects, but it does not. By interact I mean I want to be able to push the objects with the procedural mesh. – Fernando Moreira Sep 21 '22 at 19:22
  • Can you share screenshots of the components of both the sphere and the hand? Make sure the box collider, rigid body, and mesh collider components are expanded. – Vlad Stoyanoff Sep 21 '22 at 19:33
  • I posted the Screen shots. As a note the "hand" appears once it detects the coordinates data from my hand. – Fernando Moreira Sep 21 '22 at 21:17
  • What exactly happens when the objects collide when they both have rigidbody components? – Vlad Stoyanoff Sep 21 '22 at 21:34
  • When the ball has a rigid body it goes through the objects and falls out of the scene. – Fernando Moreira Sep 21 '22 at 21:52
  • Disable gravity. The bool is on the rigid body component – Vlad Stoyanoff Sep 21 '22 at 23:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/248262/discussion-between-vlad-stoyanoff-and-fernando-moreira). – Vlad Stoyanoff Sep 22 '22 at 14:20