Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

LineRenderer's Mesh Collider not colliding with ball object

Discussion in 'Physics' started by Spectra_7, Jul 23, 2020.

  1. Spectra_7

    Spectra_7

    Joined:
    Oct 17, 2017
    Posts:
    33
    Making a game where player will have to draw a line to collide with ball and fall in destination point.

    I made a script, that draws line with mouse on floor with mesh collider which gets baked at runtime.
    The Mesh Collider is successfully generated along with line renderer, but the falling ball object ignores its collision.

    Code for baking mesh of line renderer:
    Code (CSharp):
    1. Mesh lineMesh = new Mesh();
    2. lineMesh.name = "LineMesh(Clone)";
    3. lineRenderer.BakeMesh(lineMesh, wallCamera, true);
    4. meshCollider.sharedMesh = lineMesh;
    Mesh collider is already there in the line renderer prefab which spawned at runtime when drawing.
    In the above code, wallCamera is another camera in scene which helps to align the mesh collider to stand as a wall.

    upload_2020-7-23_16-39-51.png

    In above screenshot, the ball is going through.
     
    brianpmaher likes this.
  2. Spectra_7

    Spectra_7

    Joined:
    Oct 17, 2017
    Posts:
    33
    Ok I fixed it, by taking the WallCamera and rotating it 180 degrees, so that its pointing opposite side. Now the ball object is properly colliding with line renderer.

    I guess the mesh collider normals were pointing wrong side.
     
    Last edited: Jul 23, 2020
  3. zacharyaghaizu

    zacharyaghaizu

    Joined:
    Aug 14, 2020
    Posts:
    65
    Hi, How did you get to that point? I'm only get a box shape appear. Would appreciate your help.
     
    brianpmaher likes this.