- Home /
How to detect which side of my player has collided?
I need to detect, OnCollisionEnter(), whichside of my player is colliding. I've tried some things, and searched a LOT, but everyone either say:
orUse the contact points normals.
Raycast and get the normals.
For me they sound okay-ish if you want a vague description of where you are colliding (i.e. Top, Bottom or Sides). But I need to detect if the player is colliding at the front to climb walls, if he's colliding at left or right he'll do something else, and it goes on and on.
PS: I don't want to use multiple colliders as well... that's not an option in my case, unfortunately.
Thanks in advance.
Answer by tormentoarmagedoom · Mar 23, 2018 at 11:55 AM
Good day.
I've never needed to know where is the collision, but what i think is once you have the 2 objects that are colliding, you can create a vector from player center (local 0,0,0) to object, (as this post explains) and check wich components of the vector are positive/negative/zero relative to the player center point.
This way you can know if its right, left up, top, front or back ! :D
If helped, accept the answer :D
Bye!
Hey! Good day for you too! Thanks for answering really quick. I'll try your approach out, and hopefully it helps me. If it works I'll accept the answer.
Answer by fffMalzbier · Mar 23, 2018 at 11:56 AM
On the collision you get the collision position. You can transform that point to the players local space and you get a vector that tells you in what direction seen from the player the collision did accrue.
Your answer
Follow this Question
Related Questions
collisions will sometimes be detected and sometimes will not 1 Answer
How does Unity detect collision? 0 Answers
Clipping when going from one composite collider2d to another 0 Answers
Probably another "bullet through paper problem". Jerks, teleports, and other problems 0 Answers
Two different spheres attached to one object for collisions 0 Answers