How to use Triggers to allow my player to pass through a platform when jumping and land on that same platform when falling

So I’m trying to write a script that allow my player to jump from under a platform and go through it, but then land on it when falling down. I have used on Trigger Enter and Exit to control the detection but I have been unsuccessful. Below is my code and what I have tried so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlatformMovement : MonoBehaviour
{
private float forceSpeed = 5;
public bool ignoreCollision = false;
private Rigidbody platformRb;
private PlayerMovement playerMovementScript;
private Collider playerCollider;
private Collider platformCollider;

// Start is called before the first frame update
void Start()
{
platformRb = GetComponent();
platformRb.AddForce(Vector3.left * forceSpeed, ForceMode.Impulse);
playerMovementScript = GameObject.Find(“Player”).GetComponent();
playerCollider = playerMovementScript.GetComponent();
platformCollider = GetComponent();
}

// Update is called once per frame
void Update()
{

}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag(“Player”))
{
ignoreCollision = true;
Physics.IgnoreCollision(playerCollider, platformCollider, ignoreCollision);
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag(“Player”))
{
ignoreCollision = false;
Physics.IgnoreCollision(playerCollider, platformCollider, ignoreCollision);
}
}
}

If anyone has an idea on how to fix this problem, it would be really nice to hear. Thank you!

Hi!

This has already been done with the Platform Effector component, it simplifies one-way collisions and should be exactly what you want!

Docs: Unity - Manual: Platform Effector 2D

Hope this helps!