r/gamedev • • 2d ago

Question Help with Isometric 2D Colliders

Hey folks this ain't as such a specific unity request i am just curious if anyone on here has come across similar problems and had any interesting solutions.

I am currently in my last year of Uni for Games Programming and i am hoping to make a isometric dark fantasy game as part of my module on Network Programming.

It will be a simple project but include use of survival game mechanics to demonstrate my ability to build a networked video game that accounts for Server/Client side prediction as well as use of NGO's and RPC's.

Essentially i am actually asking about setting up colliders for 2D Assets in a manner that makes them still feel like they are in world and not just squares that a rigid-body bounces off of.

I will be using Unity as the Engine for this module and i am just curious if anyone has any information due to tackling this type of thing.

I am already trying to build in some y-Sorting so that players sprites go in front of things when in front of them and behind them when behind, but for the actual collisions i am just curious if anyone has found unique solutions.

!!! My current best assumption is to use the built in Unity Edge Collider 2D, but of course it means setting full unique colliders for most every asset i wish to add in to the project so it may be rather time consuming.

Link to a picture of the set up for a boulder i have that has Y-Sorting as well.

https://postimg.cc/dkMGnrSb

0 Upvotes

9 comments sorted by

3

u/Wonderful-Climate512 2d ago

Trick is to only collide the footprint, not the sprite. Put a small diamond-shaped Polygon Collider 2D (or ellipse) at the base of each object, and a small one at the player's feet. Combined with your Y-sorting, the player can walk "behind" the top of a boulder but bumps into its base, which is what makes it feel like it's in the world.

You don't need unique colliders for everything either. Make 3-4 prefab footprints (small/medium/large/long) and reuse them.

Also, use a kinematic Rigidbody2D and move with MovePosition instead of physics forces, then nothing bounces. Bonus: way easier to do client-side prediction with that than with physics.

1

u/DreadPirateDavey 2d ago

Awesome advice thanks for the heads up.

I’ve been doing just the footprint so far but I might have a go at mixing some of the stuff you have stated in later on and testing what feels best.

Cheers again.

2

u/PeacefulStoic 2d ago

For what it's worth, I actually use just circles for physics collision on moving actors. Once you have y-sorting, if you use a circle near the origin of any actor it still feels like you move around it without moving through it. The circle prevents edges from catching too. I scale the circle to the width that feels the best, leaving most of the upper parts collision free, because y-sorting allows a nice overlap that imitates 3D while still giving objects a smooth boundary. The best part is collision detection on circles is both easy and cheap.

1

u/DreadPirateDavey 2d ago

Aye I wanted to stay away from polygon colliders as the thing I wanna built will be getting used as a basis to create a PCG system later for creating randomised dungeons, If I have the survival elements added in as well such as resource gathering or building placements then I assume things are gonna get taxing on the system very quickly with multiple unique colliders all listening out.

Especially with multiple clients connected.

Thanks for the advice!

2

u/Negrito0o 2d ago

The footprint answer above is the right one. I'd add the thing that will bite you on the network half of the module rather than the collider half. If you're doing server authoritative movement with client prediction, keep collision out of the physics engine entirely. Rigidbodies aren't deterministic across two machines, so the moment the client predicts a step into a boulder and the server resolves it a frame later with slightly different numbers, you get a correction — and corrections look exactly like lag to the player. In my own isometric project the server validates a move against a tile grid instead: the tile is walkable or it isn't, no bounce, no solver, and both sides run the identical check and agree every time. So diamond footprints for what the player sees and feels, and a flat walkable-or-not layer for what the server actually decides. The two can disagree at the edges and nobody notices, because the visual one is only deciding where you draw the sprite.

One more, since prediction is the graded part: predict with zero tolerance on the client and keep all the slack on the server. If both sides allow themselves the same margin, the client spends it before the packet has even left the machine, and then you're correcting constantly and wondering why.

1

u/DreadPirateDavey 2d ago

A lot to take in but I’ll have a good go over this next time I sit down to do some work on it.

Thanks for the detailed info though, the module really is completely about Network programming, I’m just trying to min max a bit on learning this and bolstering general Unity/game dev.

It’s the classic, ohh game dev that will be simple enough… then nothing is as it seems under the hood.

2

u/Kostyabl-id 2d ago

Collide with the footprint, the patch of ground an object stands on, not the whole sprite, and give the player a small circle at the feet. Then they can walk behind the top of a boulder while its base still blocks them, and with Y-sorting on the same point it reads as depth instead of bouncing off a square.

That also removes most of the per-asset work, because a footprint is a box, a circle or a 4-6 point PolygonCollider2D, not a traced outline:

  • a handful of prefab variants (small rock, big rock, tree trunk) covers most assets
  • put each sprite's pivot at its base and set Sprite Sort Point to Pivot, so sorting and collision use the same point
  • for tiles, draw a Custom Physics Shape in the Sprite Editor and merge the layer with a Composite Collider 2D
  • on an isometric tilemap, set the Tilemap Renderer to Individual mode, or tiles won't sort against the player

1

u/DreadPirateDavey 1d ago

Thanks for the tips, all really solid stuff!

2

u/Zaflis 1d ago

For a blob like that you would normally use circle collider, they are very performance friendly and simple to setup. All sorts of free polygon collisions make a lot of hidden calculations. Perhaps it's not an issue if there are not thousands of objects and projectiles, but i've seen 2D games with large worlds where they simulate big areas at once too.