Search Unity

Collision with Platform Effector 2D

Discussion in '2D' started by davy421, Aug 1, 2016.

  1. davy421

    davy421

    Joined:
    Sep 4, 2015
    Posts:
    14
    Right now my platform with "PlatformEffector2D" is set up that when the player jumps from below the platform and lands on the platform when falling from above it. The usual stuff.

    I noticed that the "OnCollisionEnter2D" of the player activates even when the player only touches the box collider of the platform, even from below the platform, when "PlatformEffector2D" doesn't impact the player in any way.

    The problem: I need to know when the player actually lands on the top of the platform and is no longer falling, I don't need to know when the player and platform colliders touch without affecting one another. Is there any way to know when the platform and the player actually collide?

    When I don't need to know if they collided:
    dont.png

    When I need to know if they collided:
    yes.png
     
  2. Alifyz

    Alifyz

    Joined:
    May 28, 2016
    Posts:
    4
    I don't have much experience to tell you the right answer but, I think that you can use the "OnCollisionExit2D".
    This method is called when two GameObject aren't touching anymore.

    Let's imagine that our player jump into the platform and you can use this method to write a code that trigger another collider that represent the floor of each platform. I believe this can works for you.

    http://docs.unity3d.com/ScriptReference/Collider2D.OnCollisionExit2D.html
     
  3. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    432
    Why not adding another condition ?
    I think I would do something like :
    - oncollisionenter2D ?
    - velocity.y < 0 ?
    = conditions ok baby !
     
    steve-thud likes this.
  4. MarcHewittDev

    MarcHewittDev

    Joined:
    Nov 28, 2012
    Posts:
    8
    Are you simply trying to optimize so your not sending calls out constantly?

    Or are you trying to have a DoneFalling(){} type of event triggered?

    If the first, don't bother optimizing it as it's not worth the energy.

    If latter, do what RemDust suggested, a great thing I add is a get;set; property to my code called "Falling" as I do the check often throughout my code, on setting Falling to false I can trigger any special effects (dust cloud on landing)
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,487
    The PlatformEffector2D OneWay feature simply disables the contact so the physics system essentially ignores it but we still perform the callback as various users still find this useful. You can use Collision2D.enabled to check if the contact is enabled or not. When passing through a PlatformEffector2D collider, that property will be false.