Hello Guest

Author Topic: Ignore Collisions From A Specific Direction  (Read 8210 times)

oayhan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Ignore Collisions From A Specific Direction
« on: August 31, 2013, 09:24:47 am »
I'm trying to implement a very typical functionality in platform games. I want my character to jump from below a thin platform and get on top of it without colliding, but it should collide with the platform when falling from above. On a 3D world I would use a mesh collider on a mesh with only upward looking normals but I'm not sure how to do it in 2dtk system.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #1 on: August 31, 2013, 12:11:54 pm »
If you're using the polygon collider editor, you can create open shapes. That will let you create surfaces with just upward looking normals.
Check the little help box in the polygon collider editor - theres a shortcut to toggle if the shape is closed or not.

oayhan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #2 on: August 31, 2013, 12:38:26 pm »
Thanks for the quick reply. I had some progress, but still not sure what's wrong. The collision with the open collider is wrong and the the object with the box collider and rigidbody collides half way on its collider. I'm attaching an image of my problem, left one is with an open collider, right one is normal box collider.


edit: left one has a downward normal btw, so it should be passing through.
« Last Edit: August 31, 2013, 12:43:46 pm by oayhan »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #3 on: September 01, 2013, 01:40:16 pm »
Hmm... I've always had issues with single sided physx colliders in Unity - its always been really flakey for me. Can you create a simple repro case for this and email to support? Not sure if anything can be done, but I'll take a look to see if anything is set up incorrectly...

Pfaeff

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #4 on: September 01, 2013, 04:29:15 pm »
I have such platforms in my game and the way I do it is like this:



I have two Colliders. One to stand on and another (the big one) as a trigger. The latter has the script attached to it. I use it as a prefab in my tilemap, but it doesn't have a Sprite attached. The image that you see in the game is from another layer. That way I can use the same prefab for different images.

This is probably not the most elegant way to do it, but it works well.

oayhan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #5 on: September 02, 2013, 07:45:55 am »
@unikronsoftware I've attached a repro project and included a readme file with it. I don't know if it was a coincidence, but modifying the side normals slightly solves the problem (you can see it in the project).

@Pfaeff I really appreciate your solution. I would be happier if I could solve this with modifying the collider only but your solution seems simple enough too, thanks.
« Last Edit: September 02, 2013, 10:22:52 am by unikronsoftware »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #6 on: September 02, 2013, 10:28:35 am »
Hi,
Your repro case didn't have meta files and pretty much broke straight away - could you please enable meta files, zip up and send by email to support at unikronsoftware.com please? You don't need to include the library folder and the project size should be considerably smaller.

oayhan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #7 on: September 02, 2013, 10:41:54 am »
I sent the project to your email. I hope it works this time :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #8 on: September 02, 2013, 11:00:21 am »
1 - the collider depth is too low compared to the size of the collider. Increase it to 20 in the sprite collection editor and it behaves a LOT better.

2 - the red object has a mesh collider - mesh-mesh collisions in Unity don't work unless one is marked as convex. The red one is convex, so you'll need to tick convex on it.

Once those have been resolved, its doing exactly what I'd expect it to, which isn't great. Once it penetrates the surface by a certain amount, Unity thinks its on the "other side" of it and pushes it out. Try it out to see what I mean. I think you will have to solve this by other means, eg. Pfaeff's solution.

oayhan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #9 on: September 02, 2013, 11:25:37 am »
Yeah, I see your point. I guess I'll go with Pfaeff's solution.  On a side note, is there any part of manual that explains editor properties? I'm confused by terms like collider cap, diced rendering etc... I mostly try to see what it is by changing values but couldn't understand in the case of collider cap.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #10 on: September 02, 2013, 11:31:03 am »
http://unikronsoftware.com/2dtoolkit/doc/2.20/reference/sprite_collection.html

Don't think it tells you what collider caps are - the caps are just the fronts and backs of polygon colliders. The default was to leave them out as it wasn't necessary, but now it is enabled by default.

oayhan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Ignore Collisions From A Specific Direction
« Reply #11 on: September 02, 2013, 11:46:21 am »
Just what I was looking for, thanks.