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!