- Home /
How to use contact.point from 2 seperate colliders in a collision?
The purpose of the script is to retrieve and average the normals of all contact points with the ball (contactPos), so that I can get use contactPos to tell the ball what direction to jump in (away from the average of the combined contact normals). I am using this script on my ball object:
void OnCollisionEnter2D(Collision2D other)
{
contactCount = other.contacts.Length;
if (contactCount == 1)
{
contactPos = other.contacts[0].normal;
}
else if (contactCount == 2)
{
contactPos = (other.contacts[0].normal + other.contacts[1].normal) / 2;
}
}
contactPos returns the normal of the contact, and if there are 2 contact points it returns the average. This works as intended when there is only 1 contact point, or when there are 2 contact points the ball is touching are on the same collider. But it does not work when the ball is in contact with 2 points on 2 separate colliders. I believe that there are 2 separate versions of "other", and each version has only their single contact point, so at any 1 point, either version of other only contains 1 contact point. The problem I have is I can't figure out how to access each instance of the collision "other", I am unsure if thats's even the solution or reason the script isn't working.
Your answer
Follow this Question
Related Questions
Overlap point of 2 kinematic colliders 1 Answer
How do I find the point of contact on a box collider? 1 Answer
Unwanted jittery behavior 2 Answers
Colliders in a wall jut out 0 Answers
Not detecting a simple collision? 2 Answers