1
\$\begingroup\$

In my unity game I've arrange different platform ,when my player collide with upper part of the platform so platform falling down but issue that when my player collide to platform buttom of part so platform falling down.

void OnCollisionEnter2D(Collision2D target)
{
        if (target.gameObject.tag == "Player") {
        gameObject.GetComponent<Rigidbody2D> ().isKinematic = false;
    }
 }
\$\endgroup\$
3
  • \$\begingroup\$ so you want your platform to not fall down when the player collides with the bottom part of it ? \$\endgroup\$ – Uri Popov Sep 7 '16 at 9:24
  • \$\begingroup\$ yes....exact this. \$\endgroup\$ – Chetan Sep 7 '16 at 9:28
  • \$\begingroup\$ You may want to look into Platform Effectors \$\endgroup\$ – jgallant Sep 7 '16 at 9:57
2
\$\begingroup\$
void OnCollisionEnter2D(Collision2D target)
{
    if (target.gameObject.tag == "Player")
    {
        Vector2 normal = target.contacts[0].normal;
        if (normal.y < 0)
        {
            gameObject.GetComponent<Rigidbody2D>().isKinematic = false;
        }
        else
        {
            //Make player pass trough platform if you want this behaviour.
        }
    }
}

This code should work as you expect it to. I did a rudimentary test with it and it does work. Note this does not allow the player to pass trough the platform if hitting it from the bottom. I have added a comment where you need to implement this.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.