Hello Guest

Author Topic: Collision Between Two Sprites  (Read 7473 times)

MYGuy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 1
    • View Profile
Collision Between Two Sprites
« on: August 07, 2013, 07:20:09 pm »
I'm trying to have Unity print a message with OnTriggerEnter. Both sprites have colliders and one has a kinematic rigidbody and trigger. I am using transform.localposition to move the kinematic sprite into the other. They also have the same z-position and z-scale. I could get a sprite and a cube to collide perfectly, but for some reason two sprites is a no-go for me (despite hours of trying).

I'm sure it's something simple but I'm all out of ideas. Any help appreciated.  :-\

Edit: This is another case of a newbie not reading the documentations carefully enough. Per the Unity documentation:
http://docs.unity3d.com/Documentation/Components/class-MeshCollider.html
Quote
Mesh Colliders cannot collide with each other unless they are marked as Convex. Therefore, they are most useful for background objects like environment geometry.
Both of the sprites had polygon colliders, so setting to convex after the fact made them detect each other appropriately. Sorry for the trouble.
« Last Edit: August 07, 2013, 08:04:53 pm by MYGuy »

lraC

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Collision Between Two Sprites
« Reply #1 on: September 19, 2013, 09:02:31 pm »
Instead of posting a new question I'll put my question here since I have the exact same problem with the small difference that setting the colliders to Convex doesn't help. I'm a total noob. I've tried (almost) all possible permutations of settings in mesh collider/rigid body. No matter what I do I can't get OnTriggerEnter to activate.

gary-unikronsoftware

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 74
    • View Profile
Re: Collision Between Two Sprites
« Reply #2 on: September 19, 2013, 10:40:03 pm »
In addition to setting the mesh collider to convex, also make sure that the depth of the collider is sufficient which you can change in the sprite collection settings section - you can check the depth of them by viewing the sprite in the scene window.  Also, one of the sprites involved in the collision should have the 'Is Trigger' setting checked in the Mesh Collider component.

lraC

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Collision Between Two Sprites
« Reply #3 on: September 19, 2013, 11:06:06 pm »
I have checked that as well. I've been at this for most of the day. Nothing seems to work. I have read tons of posts on the forum and something that struck me was that it would be cool if you guys made some project files of stuff users often have problems with available for download. Like a file demonstrating how to set up collision detection properly :) Or just more mini-tutorials in general.

As I mentioned, I'm new to both Unity and tk2d so there might be something obvious I'm missing.

gary-unikronsoftware

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 74
    • View Profile
Re: Collision Between Two Sprites
« Reply #4 on: September 19, 2013, 11:22:20 pm »
The only other thing I can think of is that you haven't got a rigid body on the sprite you have your script attached to.  Failing that, if you create a cut down scene and export it and email it to support at unikronsoftware.com we'll have a look at it for you.

lraC

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Collision Between Two Sprites
« Reply #5 on: September 20, 2013, 08:45:06 am »
I was preparing a file to send to you, but oddly enough it worked this time! I still can't get it to work in the original game-file though... very strange. Thanks for the help anyway! :)

gary-unikronsoftware

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 74
    • View Profile
Re: Collision Between Two Sprites
« Reply #6 on: September 20, 2013, 09:08:12 am »
Glad to hear you got it working :-)