Hello.
I am still new to coding, happily class myself as a beginner, and am currently using Unity 5.5(my favourite ).
I am in the middle of a 2d project and have just finished the animation. Animation went better than I could have hoped but I can’t add a collider. If I don’t have a collider attached everything works perfectly, right animation at right time etc etc, except obviously my player won’t collide with anything. If I attach a collider then the player goes straight to the death animation and falls through the floor into oblivion.
I was originally going to use the polygon 2d collider but also tried box, capsule and mesh to no avail.
The player is a 2d sprite with sprite renderer, rigidbody 2d, animator and my player script attached.
Have you tried adjusting the scale of the collider? If it even remotely touches the ground, your player will fall through. so sometimes you need your capsule collider (or whichever collider component you’re using) to be above the feet of the player. You can also move your player up and let gravity bring the player back down to the surface.
If you elect to go without a collider, you can insert a raycast from the feet of the player and determine the distance from the collider its reading. In this instance it would be the ground, so your ground tiles would need to be tagged accordingly.
You could then create a racast in front & behind the player, like a forcefield and if anything penetrates that forcefield, you could work collisions and/or damage in that fashion.
Hi. Thank you for the reply.
I have tried adjusting the collider and trying different ones, but it doesn’t help. I actually always let my player drop a bit to get a “true” y starting position but that hasn’t helped. For some reason my player skips everything and goes straight to the “dead” animation and the script stops so the player just falls through everything.
I am not very knowledgeable with raycasting so i will look at some tutorials later, just feels like colliders would be easier as it is a very simple game anyway, they just aren’t working for me lol.
The only thing that I can think of is that you’re using a 3D collider with a 2D collider or vice-versa. If your terrain is 2D and your player is 3D, put a 3D collider on the terrain as well. ( Or vice-versa )
I cant believe that fixed it. When it wasnt working I didnt have any colliders on the screen, and my player would just collapse in the die animation and not do anything.
Its always the simple bits that I get stuck on. Thank you.
And thank you to everyone who answered.