I’m currently working on a feature for a project which requires a script that returns with a high degree of accuracy the points in the game world where “physical” (more or less anything with a mesh) game objects are in contact or overlapping with a sphere of space of an arbitrary radius.
The fact that this script requires the points of contact rather than the game objects within a volume of space is the part me and my colleague are having trouble with; running overlap sphere worked fine for getting the colliders in a particular area, but as far as I can tell, that particular function isn’t able to return contact points.
The current solution we’ve come up with involves spawning a rotating sphere collider and quickly expanding it and returning the contact points of the resulting collisions, though I suspect that approach will have a number of problems we haven’t encountered yet.
Does anyone know of a better approach to this problem?
What we’re using for this now is as follows, though I feel it’s going to have some problems we haven’t run into yet.
var collisionPoints = new Array();
function Start () {
}
function Update () {
transform.localScale += new Vector3(0.1, 0.1, 0.1);
transform.Rotate(Time.deltaTime, 0, 0);
}
function OnCollisionEnter(collision : Collision) {
for (var contact : ContactPoint in collision.contacts) {
collisionPoints.Add(contact.point);
Debug.DrawRay(contact.point, contact.normal, Color.white);
Physics.IgnoreCollision(collider, collision.collider, true);
}
print(collisionPoints);
}