- Home /
how can I instantiate an object specifically at the intersection of a collider and a mesh
Hi everyone. I would like to instantiate objects (rocks) along a mesh (mountain range). but it has to be only along the points where another objects collider meets the mesh.
my game is in 3D but I have illustrated the problem in 2D below. I want to instantiate the object ONLY where there is intercept points.
the collider will always be perfectly circular.
Answer by IxCloudxI · May 14, 2019 at 02:45 AM
Since I found the answer, I will post it here for anyone who was curious. unity stores collision points when OnCollisionEnter() is called, through a type called ContactPoint.
private void OnCollisionEnter(Collision collision)
{
if (gameObject.tag == "mountain")
{
GameObject rockClone;
foreach (ContactPoint contact in collision.contacts)
{
rockClone = Instantiate(rockPrefab, contact.point, transform.rotation);
}
}
}
Your answer
Follow this Question
Related Questions
MeshCollider Failure at high velocities 0 Answers
Correct position of overlapping meshes 0 Answers
Mesh Collider on a 2D mesh creating a 3D box? 0 Answers
Mesh Collision system seems to be buggy. 1 Answer
Mesh Collider for Voxels 1 Answer