Which is collider and which is othercollider?
This code is in a script attached to game object with a rigidbody2d and collider2d
void OnCollisionEnter2D (Collision2D collision)
{
print(collision.collider.gameObject);
print(collision.othercollider.gameObject);
}
I'm having trouble understanding which is which. If this object's collider enters a collision, shouldn't collision.collider be THIS objects collider, not the other one?
I don't need help with a specific code problem, I'm just tying to gain more conceptual understanding
Please tell if you did get the answer for this question as it's really confusing.
Answer by Hellium · Apr 21, 2018 at 01:55 PM
According to the documentation:
• collision
contains all the information about the collision (doc)
• collision.collider
is the incoming collider (doc)
• collision.otherCollider
is the other collider involved in the collision, most likely a collider attached to the current gameObject or one of its children (doc)
The na$$anonymous$$g is weird/reversed. The intuitive way I$$anonymous$$O is "other" the be the inco$$anonymous$$g one and "this" (i.e. no special na$$anonymous$$g) to be the one that is part of the same hierarchy/rigidbody that current component is.
Your answer
Follow this Question
Related Questions
Physics 2D with tile collider corner problem 2 Answers
Had to turn off gravity scale, but now player goes through walls 0 Answers
2D Physics not working correctly 1 Answer
Unmoving Colliders2D not triggering OnEnterTrigger 1 Answer
A box collider 2D (Is Trigger marked) stops my player from moving which has rigidbody 2D 1 Answer