This little trick is from something that I worked on that involved robots. So I added the Robot from Infinite Warfare (a game which I have, but need to actually finish… like all my other games!). Essentially there was a character that moved around an environment and attacked enemies. The problem was he sometimes got obscured by the environment. As it was a prototype, I made the quickest and dirtiest thing I could and whacked it in.
As the diagram shows above I raycasted from the camer to the player character. If the raycast hits anything marked “Obstacle” or equivalent term the object is deactivated.
This is SUPPPEEERRR basic. There are some cleverer things you can do like do a box cast and seeing how much an object is inside the box cast and fade it out, but if you need to get somehting up and running quickly then this is a quick and dirty implementation.
It has been a while since I have done any type of tutorial or any technical related blog post, so I thought I would share the process of how I implemented a “cloak” effect on my character. Essentially in my game, I am adding a cloak skill and in order to visualize this to the player I want a sort of holographic semi-transparent cloak effect. Something magicy and Sci-Fi. So I jumped back into my shader coding.
If you need a quick refresh of the make up of shaders in Unity then here are a couple of previous posts (with horrendous typos that I should probably sort):
First we start by creating a Surface Shader and then strip it back so it just performs diffuse lighting, a good starting point for all shader creation.
Firstly in our properties section we are going to add… well… a new property
Which will expose the following “_DotProduct” float value to the editor that we add in our CG Program.
We also want to add a _MainTex property value pair into our shader.
We also want to change the tags.
This will render the shader in the transparent rendering queue and will ignore projectors. If we want, as the player character is becoming invisible, we can also add the “ForceNoShadowCasting” tag that will mean the object does not cast shadows.
We also want to disable the expensive PBR in this shader and switch it out for Lambertion reflectance before telling the CG program this is a transparent shader and then finally disable the lighting. Wow that was a long sentence.
The last thing we want to do before we actually jump into our surface function is change what actually gets run into the shader. In this case we want the world normal and view direction as well as what is already there.
Cool, now we whack this code in the surface function.
And we get this effect:
On a sphere it looks pretty basic although it makes a cool atmosphere effect one, similar to the one I used in my seasonal globe:
What this shader is doing is actually showing the silhouette of the object. If I swap the circle out for something else and we move around it we can see the outline changes.
After I tweaked the values a bit and applied it to my asset store model, here is what I got:
The gif doesn’t do it as much justice as in-game, but I actually think this is quite cool and that shader is cheaper than the previous refraction shader I was using.
I also had a little experiment for fun with my enemy model by adding a wave to all the verts and made what I am calling the “Demontor” shader
It is common knowledge that I work on mobile games and of course Android is one of the platforms we develop on. And from time to time we need to break point our code whilst it is running on device. Today however, I couldn’t remember how you do it. So I headed over to the Unity Manual, but there was lack of information how to do this in Visual Studio. It tells you how to easily attach to the MonoDevelop debugger, but not the Visual Studio one. So we went looking for a way to do it. Unity Answers post does tell you how to do it, but it isn’t particularly well worded and also starts of with “I just went back to MonoDevelop” which quickly makes you stop reading the rest of his/her answer.
This is how you do it.
First follow the steps on this page of the manual: