Friday, January 24, 2020

unity - How to create custom 3D "areas" at runtime


I've been puzzled for a few days trying to solve this problem, so far with no results.


On a map, currently a Terrain, I'd need to have some "areas" which can be controlled by a specific players. The shape of those areas can arbitrarily change during the course of the game, such as you add a marker in any point, and the area evolves (like a spline, say) to pass through that point too.


The problem isn't drawing the boundary itself, of course, but having the GameObjects detecting the area they are in.


Currently I have absolutely zero idea on how to make this exactly.




I've thought about a nice approximation, which is splitting the terrain in fixed chunks, and having the player control them "chunk by chunk": every chunk can have its own collider, and that should be easy if not trivial. So the question is how to do it "properly", since I already have this workaround.




Answer



I solved this problem using an hybrid approach, inspired by:



  • my original workaround

  • @Felsir's post

  • @dnkdrone.vs.drones's post



I have Chunks, which may have an owner or be contested.




  • Inside a contested Chunk, different players have their areas of influence.

  • Instead of using a definite polygon/line border, inside the Chunk itself every player may place Flags.

  • The Chunk itself is dividend into equally distanced ChunkPoints.

  • A ChunkPoint's owner is the nearest Flag's owner.

  • Chunk's % ownership is how many ChunkPoints you own.


first screenshot screenshot with sub-areas



Using a polygon approach turned out to be too complex because I had to detect the order of the points, and they could with time take very complex shapes, which wasn't obvious how to handle.


I considered using voronoi's before realising that a ChunkPoint map was much easier and equally good for what I needed to do (but trying to use them was the source of inspiration that got me there).



In the original workaround idea, Chunks weren't "contested", they were just fully-owned by a single player, and that's why I didn't like them.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...