- Home /
i want to know object's collding side!
When play collide with object, i want to player work differently. If player collide with upside, then player's speed get up. But palyer coliide with downside, player's speed get down! If you know function that can get object's colliding side(up, down, left, right), please help me!! I use C# language.
Answer by JVene · Jul 10, 2018 at 11:39 AM
In OnCollisionEnter, the Collision parameter includes Contacts, a list of points of contacts and information about what was colliding. From there you can deduce where the contact occurred.
If that is too complicated to use (and sometimes it's just not that simple), you could simply put different colliders on the two sides which gives you two different scripts, one for the upside, one of the downside, which makes this quite obvious and simple.
I am found about Contacts , but ,i think, it just can get a point of colliding. I am finding solution really hard, but they just give me solution about a point ,not a edge. I want to make game like Super$$anonymous$$ario. And i dont use physical 2D gravity for some reason. (Player move from transform.Translate.) When player contact ground, player just stick to ground whatever colliding side is. For that reason, i want to get colliding side(edge) to solve my problem. I should solve my problem from a point? if so, i try to that way. But i dont know there are already made function. In Contacts, can i get information about colliding side(edge)?
A point can identify a side, so yes you can solve this problem with a point of contact. You can start an evaluation by using OnEnterCollision, and look at the list of contact points. They're in global coordinates, but you can transform them into local coordinates to see the relevant location of the impact. With your knowledge of the model, you should see obvious patterns about the coordinates you see that identify the side of the contact. Think of this another way, if you selected a point on the model, could you tell where that point is?
However, re-read my original answer for option 2. I think it is more appropriate for you.
You should consider placing multiple colliders at the key positions you want to sense. Consider them sensors you install to cover the important parts, up/down/left/right. Now, when the up collider is hit, that's the collider that gets informed. The decision about which collider has been hit is made for you. It's much simpler.