Hello Guest

Author Topic: Collisions with Animator  (Read 6362 times)

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Collisions with Animator
« on: July 12, 2014, 09:07:22 pm »
I have a Sprite with animator that I have applied a box collider 2d to.  I haven't setup colliders for each frame as assume a collider to the animator is possible.

I have setup a game object with a box collider 2d as a boundary and it just doesn't collide, just passes through each other.

Is it not possible to add a collider to the animator but instead have to do it for each frame of animation?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with Animator
« Reply #1 on: July 12, 2014, 09:45:44 pm »
You can add it to the animator fine, but make sure the sprites have user defined for collision, and not None. Also, make sure you have your rigid body set up as you need it.

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Collisions with Animator
« Reply #2 on: July 12, 2014, 09:54:47 pm »
In fairness as I have it

I have about 64 frames of animation and they are all setup as follows

http://imgur.com/4LcweKk,qyhXvCc,8H1hZkm#0

This is my boundary setup

http://imgur.com/4LcweKk,qyhXvCc,8H1hZkm#1

This is the sprite with animator with collision applied at animator level not individual sprite in sprite colleciton.

http://imgur.com/4LcweKk,qyhXvCc,8H1hZkm#2

No joy unfortunately.

Not sure if thats helps but if I rest my player on the boundary it slides to rest of where the collision stops.  But doesnt prevent it from entering where the boundary is
« Last Edit: July 12, 2014, 10:07:47 pm by mygamingproject »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with Animator
« Reply #3 on: July 12, 2014, 10:29:53 pm »
What does the collider look like in the scene? I just tested this using the demo assets and it seems to work as expected? the collider remains static while the animation plays, and collisions seem to work fine. Try reproducing the issue using the built in assets - if you can, post the repro here and I'll take a quick look. Maybe I'm misunderstanding the issue.

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Collisions with Animator
« Reply #4 on: July 12, 2014, 10:56:27 pm »
I don't think you are misunderstanding its a simple scenario that for some reason isn't working

The collider on the animator (box) is highlighted round the asset as expected.

The box collider for the boundary is an empty game object which has a box collider attached.

Looks like this in the scene

http://imgur.com/rRk4LBX,mXEShjV#1

and this is its settings in inspector

http://imgur.com/rRk4LBX,mXEShjV#0

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Collisions with Animator
« Reply #5 on: July 13, 2014, 10:04:23 am »
Further developments but even more confusing

I have created a new project using a sprite with animator applying rigidbody2d and box collider 2d as well as creating boundary with a box collider 2d.  This works as expected.

Reproduce exactly the same scenario is my project using the same demo assets and still it doesn't collides it has an effect of when it reaches the point of intersection the player looks like he is moving in mud and then when passed the boundary carries on normally.

The only difference I can see if that the scale of the assets and potentially the sample project I setup at 2D environment and the one I am having issues with 3D.  Although I am ensuring the z plane is the same but not sure that matter with 2D colliders.

I have also added the following script to my player:

Code: [Select]
public class CollisionTest : MonoBehaviour
{

void OnCollisionEnter2D(Collision2D coll)
{
Debug.Log ("In here");
}

}

and this does get fired so the collision is occurring just the objects aren't being stopped. They aren't marked as triggers either.

Any thoughts?
« Last Edit: July 13, 2014, 10:11:44 am by mygamingproject »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with Animator
« Reply #6 on: July 13, 2014, 11:51:32 am »
How big are your sprites (pixels per meters), try it closer to 100 if its very far off. If you're still stuck create a simple repro case and post it here.

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Collisions with Animator
« Reply #7 on: July 13, 2014, 01:27:24 pm »
OK I'll try it. So I guess Pixel to meters set to 1 isnt helping me then.  This is however is a convenience setting that is implied within your camera tutorial as its a direct correlation of pixel locations to world positions.
« Last Edit: July 13, 2014, 01:44:10 pm by mygamingproject »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collisions with Animator
« Reply #8 on: July 13, 2014, 09:18:13 pm »
1 pixel per meter does work, it should just move very very slowly. The collisions should still work...
Post a repro case and I'll investigate this further. This should work.