Hello, I am trying to make a player character collide on some platforms only from the top and ignore any other collision for a 2D-style game. I came up with this solution as a script attached to the platform(s)
What I don’t like about this is the fact that I’m checking for the player’s position relative to the platform on every frame. My question is: Is there a better way to do this?
The best way I’ve seen this done is with Physics.IgnoreCollision. IgnoreCollision can be set to true or false, and can control if an object colliders with or ignores another collider.
Let’s say that you have a platform, made from a simple Unity box. You parent a trigger object to the box, looking like this:
In scripting, you say that if your character enters the trigger (OnTriggerEnter), use Physics.IgnoreCollision to make the character ignore the platform’s existence. When the character leaves the trigger (OnTriggerExit), use Physics.IgnoreCollision again (set to false) to make the character able to collide with the platform again.
I’ve made a tutorial recently on efficient one way collider with source code available on my blog. It’s based on Faricho’s idea and it’s the most wfficient way of creating one way colliders. Youca check it out on my blog. Link – Click here to see it
What u can do is make a collider just below the platform to check if the player is colliding the platform from below so that We can disable the platform at that time, try out this tutorial Newtonians' Blog 3D: One Way Platform : Unity Tutorial