How to generate colliders for dynamically generated / editable world (i.e Terraria)

Started by
1 comment, last by TeaTreeTim 3 years, 11 months ago

So I am using Unity and trying to build a world system similar to Terraria. I have already tried using Unity built-in tilemap system however the performance was lacking for the world I wanted to be able to generate so I decide to just go ahead a build a custom solution. Right now I have the ability to generate the data for a map at the size I want and am just using meshes to render the world chunks (60 x 60 tiles for each chunk). I can also edit the world at runtime (like mining / building). All that works however the issue I am running into in being able to generate the colliders for the world.

Every tile either has a collider or does not and I have access to that data from the multi-dimensional array that stores the tiles information for each chunk but each solution I have tried just does not handle the the use cases for the colliders I want to be able to generate.

As an example take this:

OOOOO
OXXXO
OXOXO
OXXXO
OOOOO

Xs have colliders and Os dont. I want to be able to generate an edge collider on the outside (so at points of 1x1, 1x4, 4x4, 4x1, 1x1) and on the inside (or points 2x2, 2x3, 3x3, 3x2, 2x2).

How would I go about being able to generate collider for this kind of system at runtime (or should I be using something other than colliders for collision detection that make this easier)?

Advertisement

EDIT: NVM I just looked at Terraia pics and my post was not helpful

This topic is closed to new replies.

Advertisement