Hello, I’m relatively new to unity, but I have a lot of experience in applied programming like robotics. I’m trying to make a 2D platformer with controls and gameplay that is “done right”. However, the first major problem I have hit in that goal is ground detection. I’ve been spending hours over the past few days thinking about what the best way to go about this is.
Casting - Extends beyond the bounds of the player.
- RayCasting - Doesn’t cover the entire bottom of the player
- CircleCasting - Inconsistent distance depending on player shape (rectangle)
- BoxCasting - Inconsistent distance depending on player shape (circle), doesn’t need to start with a box, would make a lot more sense if it were casting a line perpendicular to the casting direction.
Collision Layer - Most consistent, but it only needs to be a surface, not an area, and it is tedious to paint a layer everywhere you want the player to be grounded.
Basic Collider Logic - No good way of telling where the “bottom” of your character is.
My idea for how to make a perfect ground detector: A collider that replaces a paintable edge on the character so that whenever that collider hits an object in the ground layer, the character is grounded. However, there are two problems. One, I’m not sure how to go about replacing part of a collider and I doubt unity has official support for this (I’m very open to making custom functions, I just need help on where to look). Two, the built in edge collider for unity doesn’t detect collisions with other edge colliders or composite colliders which is a huge problem because many 2D games us tile maps with composite colliders for collision.
Any other ideas for making the ground collision more modular/flexible/expandable? I’m open to suggestions. Mostly, I need help figuring out how to actually go about implementing this. I haven’t programmed a collider from scratch before so this would be very new to me, though I have the computer science and mathematical background to figure it out with a little help on where to look.
I’ll also make sure to post my solution here when I’m done.
Thanks in Advance
MidnaTheBlackRobe