Hi all,
I tried to find the right title for this thread and I realized it is actually hard to do so I hope I will be better at explaining.
I am building an defense game where enemies targets a sphere and where the player has to build a shield around it to protect the sphere.
In my current design, the shield is an actual object made in 3dsmax, composed of of pentagons and hexagons (I think it is a geosphere but I believe there is a much more scientific word to describe this shape), see attached. Each “face” or “tiles” (so either a penta or an hexa) is an individual sub-mesh of the parent shield object, and has a mesh collider attached. The player can only interact with the penta (I call them “generators”).
What I am trying to achieve here is when a player “activate” two aligned pentagons, the hexagons in-between activate as well.
Details as (see 2nd attachment):
beginning of the game, all tiles are de-activated (mesh renderer turned off)
player activates tile 1 → turns on the mesh renderer on tile 1 (activates tile 1)
player activates tile 2 → turns on the mesh renderer on tile 2 (activates tile 2) → activates tile 3
player activates tile 4 → turns on the mesh renderer on tile 4 → activates tile 5 and 6
If all the hexa between 2 penta are de-activated as a result of the enemy hitting them, the associated penta are de-activated as well. I really hope that makes sense.
I managed to do this and it is working fine, even though as I was coding I felt like I was overthinking the design. I did it by literally referencing “associations” between tiles and checking whether or not they were active every time the shield is hit by the enemy.
I feel like this is not the best way of implementing this, but I can’t find any other way of achieving this design. Especially when you think scaling: currently the shield object is very simple but I intend to subdivide it more resulting in more than 1 hexa between 2 penta and I don’t thin the current implementation is sustainable.
Is there a genius out there that would care helping a confused mind?
What about on hit to X penta, raycast to N neighbours by penta edge, if n is activated turn off.
You could have an associate array and when the owner of the array is turned off all observer tiles turn off or any other version of the observer pattern,UnityEvents
But If I understand the system it’s kind of how you take a piece in checkers but chaining so activating every other penta activates those in between to all edges of the penta. I think the raycast would be better.
get the surface normal of all shield panels and generators.
for each panel P, subtract its surface normal against each generator G’s surface normal.
Vector3 compare = panelNormal - generatorNormal;
the 2 generators that result in the smallest compare.magnitude will be the 2 generators that affect panel P.
Edit:
From there each generator should have a event telling if the generator switched state
Then you just simply have P register with those 2 generators. and when it receives an event from either it checks if both are on.
Edit 2:
Furthermore if you take that shape you posted and subdivided the panel, it would not affect which generators affected it. you could take panel 3 and then subdivide it five, ten, even a million times and then color code which parts of that panel were affected by generators 1 and 2. and it would still form the shape of a hexagon.
Thats just an intrinsic property to that type of polyhedron. which means you can get away with still using a single “macropanel” object to evaluate if all the subdivisions should be active or not. possibly use some sort of animation or parametric equation to handle the individual animation of the subpanels activating/deactivating.
@JoshuaMcKenzie , I do believe you are on to something. However when I am talking subdivision, I am not refereing to dividing the panel itself, but the whole polyhedron - resulting in more pentas and hexas (but still following the same rule of “triangles” with pentas as points and edges / surface as hexas.
@sweetclimusic , I have no experience with UnityEvents but I shall look into it.
I am starting again from scratch to see if I come up with an implementation when the time comes. I shall keep this updated.
Thanks.