With the damage system in place, one thing that became apparent was that the spheres players controlled would become difficult to see over time.
1. Starting situation of a match:
2. Yellow takes some damage, it becomes harder to see:
3. Yellow is completely destroyed, it’s now technically almost invisible:
4. And even worse, its shadow has disappeared, so the yellow player cannot even figure out where the sphere will land!
OK, I had to fix this. Most of the shaders here are taking advantage of PBR (Physically Based Rendering), so I have all of the pretty lights, shadows and the Z buffer all nicely managed by the Unity Standard Shader. It would be a problem if I added some other material to the sphere that transparent yet fully visible. Don’t get me wrong, it’s possible, but I didn’t necessarily want to invest too much time into this. So I came up with a cheap solution, both in terms of effort invested and performance. Before I reveal what it is, here’s how the solution looks like…
1. This is when the spheres have taken no damage:
2. This is how the shadows look like when the spheres are intact:
3. This is how the spheres look like when they are damaged:
4. And they are visible when they are completely destroyed! And they have a handy shadow too:
How do you think I accomplished this? Take a moment to develop a theory BEFORE you read on. Feel free to let me know what you think I did in the comments, I’m curious! 😀
So here how I did this:
That’s right, two 2D planes, or, more precisely, two quads!
1. The first quad has a transparent PBR material on it with a circle-like texture on it. The important thing about it is that it must be constantly looking at the camera, so it appears to the players to be correctly rotated all the time. It is also important that this quad cast no shadows. It doesn’t need to receive them either.
2. The second quad is the horizontal one. This also needs to maintain a rotation constantly. It needs to always point up. It has the same material as the other quad, but its render settings are set to Shadows only. So it’s invisible to the players, but it always casts that round shadow.
Of course this is possible because MC2 has spheres as characters and a perfectly vertically oriented directional light for gameplay reasons (the shadow is exactly under the player), but this was a pretty neat trick and I’m generally happy with the result, as none of the playtesters were able to spot the tickery.
And here is ALL of the code that makes this trickery possible:
Just two lines:coreQuadRenderer.transform.LookAt(
So to recap:
4 polygons (2 triangles)
1 material (1 extra draw call)
2 lines of code in Update()
I think this was a cheap and fun solution to make! And it seems to work. Hope this comes handy for someone else in future.