LineRenderer's Mesh Collider not colliding with ball object

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:

Mesh lineMesh = new Mesh();
lineMesh.name = "LineMesh(Clone)";
lineRenderer.BakeMesh(lineMesh, wallCamera, true);
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.

In above screenshot, the ball is going through.

1 Like

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.

Hi, How did you get to that point? Iā€™m only get a box shape appear. Would appreciate your help.

1 Like