Hello Guest

Author Topic: Collisions with custom box colliders on non moving sprites  (Read 12088 times)

stephankrohn

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Collisions with custom box colliders on non moving sprites
« on: September 25, 2012, 12:59:52 pm »
I've got an issue with an animated sprite, that uses the custom box collider only on some frames. It seems that the physx engine doesn't detect any collisions if the GameObjects (or more likely the attached rigidbody's) don't move. I am playing a sort of hit animation while the sprite is not moving. This won't register any collision or trigger events. If I do the same thing with a moving sprite it works. Is there any other way to fix this problem other than applying constant micro translates to the GameObject?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #1 on: September 25, 2012, 11:45:22 pm »
If you have a custom collider only on some frames, then I think you'll need a rigidbody to be present and set to kinematic. I haven't actively used this since Unity 3.4, so it is possible that some things I did are incompatible with 3.5.x. Let me know if it works or not, I will investigate further if it doesn't.

stephankrohn

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #2 on: September 26, 2012, 08:51:34 am »
It actually has a kinematic rigidbody as otherwise there wouldn't be any collison detection anyway. The problem seems to be that just changing the position of the collider from the collider component itself doesn't seem to update the physics simulation. Probably it thinks that since the rigidbody itself didn't move it doesn't have to do something. You can simulate this in the editor. Just hit play and try creating collisions by moving the GameObject (which works) and changing the colliders position/size (doesn't work).

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #3 on: September 26, 2012, 05:00:35 pm »
Ok. I'll look into it. What about disabling and enabling again when it is moved? I vaguely remember trying a bunch of things before settling on this.

kenshin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #4 on: May 21, 2013, 10:31:11 pm »
Hello,

I have also same problem, but 2 animated sprites and both have rigidbody attached and trying to collide with each other. the setting is nearly same as explained above and:
- I have 5 frames and 3rd frame is a hit frame having custom a box collider. other frames has "force none" collider,  I have also tried box trimmed for frames other than hit box.
- I have tried enabling/disabling box collider itself

but all tries failed. OnTriggerEnter, OntriggerExit doesnt work. OntriggerStay also doesnt work, it always show stay event. And I also tried box trimmed for hit box but all other "force none" collider, it doesnt work untıl ı move the object a little bit.

could u please solve my problem ?
« Last Edit: May 21, 2013, 10:50:24 pm by kenshin »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #5 on: May 22, 2013, 12:08:39 pm »
Is it set to kinematic?
Can you send me a repro case to look at? (support at unikronsoftware dot com)

kenshin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #6 on: May 22, 2013, 02:07:27 pm »
Yes for both objects.
I will send an example tonight. In addition, z coordinate is also same and in length 0.2.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #7 on: May 22, 2013, 04:16:56 pm »
An example would be most excellent. Will save both of us a lot of time.

kenshin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #8 on: May 23, 2013, 07:52:22 am »
I have sended nearly 60 mb e-mail to support adress.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #9 on: May 23, 2013, 10:17:37 am »
Thanks I'll investigate that.

drmrboyc

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #10 on: August 15, 2013, 08:26:52 am »
Hello,

Did you have a chance to dig deeper into this issue yet? I'm running into the same problem with a custom box collider in a tk2dSprite with Animator. It will activate the trigger with the player's character controller a few times, then once the player stops moving, it will no longer register trigger events.

Thanks a bunch!

EDIT: This might have something to do with the destruction/recreation of the box collider happening on the collider it previously "triggered" with. I only suspect this, b/c sometimes I am able to cause the OnTriggerStay event to keep firing, however the OnTriggerEnter, never re-fires after a few times.  To recreate, create a sprite animtor with an overhand sword swing, with the sword being the box collider, then move a character controller well within the range of one frame that contains a box collider. It should register a few OnTriggerEnter's, then stop, sometimes continuing to register OnTriggerStay's.
« Last Edit: August 15, 2013, 08:49:25 am by drmrboyc »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #11 on: August 15, 2013, 01:43:57 pm »
You shouldn't really animate box colliders unless you are really careful about it. Do you have a kinematic rigidbody attached to this?

drmrboyc

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #12 on: August 15, 2013, 05:35:26 pm »
Do you have a kinematic rigidbody attached to this?

I'm not 100% sure, but I don't think I do. I'll explain my setup and maybe you can point me in the right direction.

I have an enemy Sprite with Animator. I've manually put a Capsule Collider on the sprite so as to detect when the player strikes the enemy. I've also used the 2dtk Sprite Collection to create a box collider which covers the enemy's weapon in each frame of the enemy's attack. This box collider catches when the enemy strikes the player's collider. They are all setup as triggers, as I don't want to use actually collision physics in combat.

The problem I'm running into is when the player's capsule collider stands next to the enemy and the enemy's box collider is spawned on top of the player. Basically, the enemy is swinging and after a couple of swings, if the player doesn't move, the box collider will stop registering triggers.

I can make/send a video for further explanation if that would help?

Thanks a bunch!


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #13 on: August 15, 2013, 06:10:40 pm »
Add a rigid body component to every collider you have, and tick kinematic on all these rigid bodies. Try that again and see if it helps?

drmrboyc

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Collisions with custom box colliders on non moving sprites
« Reply #14 on: August 15, 2013, 08:43:52 pm »
That was exactly what it needed! It now works precisely how it is supposed to. I read about the Kinematic Rigidbody, but didn't try it b/c I'm using triggers not collisions. However, I see now that it is necessary for any situation. Much appreciation for your help!

I don't suppose you could briefly explain why, or point me to some literature that explains why, all colliders should have a rigidbody attached? I would definitely like to increase my understanding!

Thank you very much!

EDIT: Nevermind! I easily found some links that explain the whole concept quite efficiently. I will include them here for anyone who may find value:

http://answers.unity3d.com/questions/40448/why-attach-a-kinematic-rigidbody-to-a-collider-tha.html

http://docs.unity3d.com/Documentation/ScriptReference/Collider.html
« Last Edit: August 15, 2013, 08:56:23 pm by drmrboyc »