I’m trying to allow a 2D player drop down from a platform with the push of a button. It works, but it is very unresponsive. If I were to stand in one spot and try it, nothing would happen. If I zig zag back and forth I could potentially fall through, or just partially, and if I push the button just before I land on the platform from jumping I will go through it with no problem. Is there anyway to let him drop with movement or momentum and still be responsive?
*Updated Script
using UnityEngine;
using System.Collections;
public class JumpThroughPlatform : MonoBehaviour {
public string platformLayer;
public Transform groundCheck;
public float groundCheckRadius = 0.1f;
private int playerLayer;
private int platLayer;
private bool canDrop;
void Start () {
canDrop = false;
playerLayer = gameObject.layer;
platLayer = 1 << LayerMask.NameToLayer (platformLayer);
}
void FixedUpdate () {
// Setup for one way platforms
bool grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius);
bool dropButton = Input.GetKeyDown (KeyCode.S);
StartCoroutine(dropDownFromPlatform (dropButton, grounded, 0.5f));
Physics2D.IgnoreLayerCollision (playerLayer, platLayer, !grounded || rigidbody2D.velocity.y > 0 || canDrop);
}
IEnumerator dropDownFromPlatform (bool isDrop, bool ground, float waitTime) {
if (isDrop && ground) {
canDrop = true;
yield return new WaitForSeconds(waitTime);
canDrop = false;
}
}
}