2D Toolkit Forum
2D Toolkit => Support => Topic started by: mygamingproject 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?
-
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.
-
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
-
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.
-
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
-
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:
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?
-
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.
-
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.
-
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.