🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

[Unity] 2D composite colliders and edge clipping

Started by
4 comments, last by zuhane 4 years, 7 months ago

Hello people!

Thanks for taking the time to read this post. I've been using Unity for a while now and I must say that I'm very impressed with it. Definitely a jump up from XNA. However, something that I've noticed that leaves a lot to be desired is the 2D tile-based collision. Below is a little video of a game I've been working on with a friend which demonstrates my problem. Essentially, games that use huge open planes and polygons don't seem to have many problems with collisions, but when a game consists of lots of small tiles stacked alongside each other, objects tends to get stuck in-between the gaps. For example, if I have a horizontal strip of little tiles, and the player runs along the top, sometimes he'll come to a standstill and have to rebuild his momentum, However, this is much more noticeable for the ball. The ball seems to consistently bounce around randomly by hitting into edges, due to the nature of how fast and random it moves, making it very hard for players to line up shots and make meaningful choices in how they attack the ball.

So after doing a little Googling, it seems like there's absolutely nothing on this topic. It baffles me, because tile-based platformers seem to be everywhere on Steam! So after some more digging, I saw that many people were using composite colliders, so that after the level is generated, the tiles all merge together into one polygonal/composite collider. However, I've found that this problem still occurs even when using this method, especially near corners. Am I possibly overlooking a simple solution here? This has been giving us grief for months now!

It's also worth mentioning that composite colliders create another problem within our game world. The blocks within the levels are meant to be damaged upon contact with the ball. However, when these are nested inside an object using a composite collider, none of these collisions fire off any more, essentially making all the blocks in the level indestructible. Is there a way to cycle through all of the colliders inside of a composite collider to check them individually? Any help would be mundo appreciated.

 

 

 

 

Advertisement

Unity Physics are not the best for a platformer. I don't think that many people actually use them outside prototyping. I personally prefer to use custom movement controllers, and not rely on the physics. Check out this tutorial and you will get the idea: https://learn.unity.com/tutorial/live-session-2d-platformer-character-controller

Thanks for the reply! I'm thinking of creating a custom character controller from scratch. However, wouldn't that mean that I'd then have to write a whole physics system to be able to bounce multiple balls around? The whole reason I switched to Unity was because of the physics system. I'd have to learn A-level / degree-level physics, rigid body maths, collision resolution, angular velocity, etc. Could a hybrid not work?

 

Yep, a hybrid would work. That tutorial I send you kind of does that. While you will have to do the movemetns, boucing etc. yourself, you can (and probably should) use the collision detection of the physics system. That is what I usually do anyway. On the other hand, there is a game called Robbie Swifthand And The Orb of Mysteries. They did use the physics system for everything, and the game looks and plays pretty nice. Unity promote it pretty heavily because of this. So it is possible to use the physics system, but I'm not really sure how :)

Thanks, Antonsem. I'll have a look into that. Might also try the hybrid approach that I've seen and see if that helps.

 

This topic is closed to new replies.

Advertisement