cjddmut / Unity-2D-Platformer-Controller

A customizable 2D platformer motor that handles mechanics such as double jumps, wall jumps, and corner grabs. Includes a player controlled prefab that can be dropped into any scene for immediate support.
MIT License
873 stars 163 forks source link

Drop through one-way platforms #19

Open thelucre opened 9 years ago

thelucre commented 9 years ago

The classic way, by holding down and jumping.

cjddmut commented 9 years ago

I've thought about this and I think the solution I plan to go with is allowing something to tell the motor to pass through the platform its on....how the motor is told that (could be by holding down and jumping) is up to the script interfacing with the motor. Good suggestion

digiwombat commented 7 years ago

Old ass post, but I'll throw in a version I'm using for some early dev for anyone who keeps looking at this Issue and wants something to get it working.

In Update():

if(Input.GetAxisRaw(PC2D.Input.VERTICAL) < -0.5f && Input.GetButtonDown("Jump"))
{
    StartCoroutine("FallThrough");
}

Then add this:

IEnumerator FallThrough()
{
    SetLayerRecursively(GameObject.Find("One Way Platforms"), LayerMask.NameToLayer("Decorations"));
    _motor.Jump(0.01f);
    yield return new WaitForSeconds(0.1f);
    SetLayerRecursively(GameObject.Find("One Way Platforms"), LayerMask.NameToLayer("Environment"));
}

public static void SetLayerRecursively(GameObject go, int layerNumber)
{
    foreach (Transform trans in go.GetComponentsInChildren<Transform>(true))
    {
            trans.gameObject.layer = layerNumber;
    }
}

Changes my layer to a non-collision layer, then jumps a tiny amount so the gravity of the motor kicks in.

It ain't pretty, but it should work for me for the most part. Especially considering I won't have too much in the way of OneWay Platforms.

Oh, and make sure you change your Jump command in the player controller to not jump if you're pressing down.