Hello Guest

Author Topic: Help with animated sprite collision  (Read 6089 times)

Bob_Shanky

  • Newbie
  • *
  • Posts: 5
    • View Profile
Help with animated sprite collision
« on: August 25, 2013, 09:16:29 pm »
Hello,

I am making a beat 'em up game and am having some issues with collision of the animated sprites. I have a kick animation set up with a box collider in 3 of the 12 frames which is used to represent the attack collider. I have an empty game object with a box collider attached to the animated sprite as a child object to represent the hitbox. When I place two animated sprites next to each other and trigger the kick animation no collisions are registered. However, if I trigger the kick animation while translating one of the characters into the other then the collision is registered. Any advice? I have a script attached to the animated sprites which just has a call of OnCollisionEnter that writes "test" to the debug log.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help with animated sprite collision
« Reply #1 on: August 26, 2013, 02:13:45 pm »
Do you have a kinematic rigidbody attached object?

Bob_Shanky

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with animated sprite collision
« Reply #2 on: August 27, 2013, 12:39:31 pm »
The object has a rigidbody but it is not kinematic.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help with animated sprite collision
« Reply #3 on: August 27, 2013, 12:41:02 pm »
If its not kinematic and you're animating it, things will go horribly wrong.

Bob_Shanky

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with animated sprite collision
« Reply #4 on: August 28, 2013, 09:55:41 pm »
I made the object colliders kinematic but now collisions aren't registering at all. I'm fairly new to unity so I'm going to do some more research on colliders and animations.

Bob_Shanky

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with animated sprite collision
« Reply #5 on: September 02, 2013, 04:28:40 am »
Here is where I stand: two players with a Character Controller and a kinematic Ridigbody. Each player has a script called OnCollision which has one function call to OnControllerColliderHit(ContollerColliderHit) and one function call to OnCollisionEnter(Collision), each with it's own separate debug log message. When one of the players is moving and a collision occurs, it registers correctly. However I still cannot register any collisions when both characters are standing still and an attack animation connects with one of the characters.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help with animated sprite collision
« Reply #6 on: September 02, 2013, 05:02:19 pm »
That is an issue with the physics integration in Unity - it doesn't mark the collider as "updated" when it is just resized which is what happens when you animate this - generally physics engines don't like changing colliders. You can get around this by moving your sprite a tiny bit every frame, or creating the collider as a child of the object and moving that instead.

How are you using this? Some pics will really help explain whats going on - as there might be another solution to this.

Bob_Shanky

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with animated sprite collision
« Reply #7 on: September 03, 2013, 03:43:50 am »
http://imgur.com/VY9QmaG&g9eGicn#0
Here are two screenshots of the characters. Forgive the crude graphics, this is pre-alpha :P. The first picture shows both characters with their Character Controller outlines. The second picture shows the kick animation collider clearly intersecting the Character Controller of the second character. I removed the original extra child collider because I read that rigidbodies always register OnCollisionEnter which is why the OnCollide script has a call to OnCollisionEnter as well as OnControllerColliderHit.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help with animated sprite collision
« Reply #8 on: September 03, 2013, 02:25:43 pm »
How are you defining the box collider?

If you want to detect collisions between hand and other parts of enemy, your best bet might be...
1. Create a sprite, use character controller, or whatever you like here.
2. Use the attach point feature to mark out the arm / leg, etc. (Check http://unikronsoftware.com/2dtoolkit/doc/2.20/reference/sprite_attach_point.html for more info).
3. Create sprites to use the above.

 You will now have these game obejcts animating properly - you can attach normal Unity rigidbodies / shapes there to say "this is the hand" and so on, tagged as triggers if you need it - if you just need to find out if you hit something, triggers are better than colliders.