Hi all. I am trying to fade my object’s transparency in / out depending on how close the Cinemachine camera is to the target? Can I see an example using the Free Look?
Thank you!
Hi all. I am trying to fade my object’s transparency in / out depending on how close the Cinemachine camera is to the target? Can I see an example using the Free Look?
Thank you!
Look at our FadeOutNearbyObjects sample scene.
Window → Package Manager → Cinemachine → Import samples.
@gaborkb : I know how to do that already. What I’m SPECIFICALLY asking is how to add TRANSPARENCY to the player object depending how close or far the Cinemachine camera is to the target when zoomed in / out OR the camera drags across the floor and zooms in or out. I don’t want to fade in / out OTHER objects, I want to fade in / out the PLAYER if that makes sense. Much appreciation!
P.S. I am not seeing ANY example through the search tool in Unity, " FadeOutNearbyObjects"
FadeOutNearbyObjects sample uses a shader to fade out materials based on the camera’s location.
In the sample scene, click on FreeLook Camera. At the bottom of its components, you’ll find CinemachineFadeOutNearbyObjects script. This script has a couple of parameters that you can use to fine-tune this effect.
By default, this script is using the FadeOut material, but you could change it if you want. By default, this material is used by all the objects in the scene, but the player.
You can assign this material to your player and then your player is going to fade out depending on the camera’s location.
In Unity, on the top bar: Window → Package Manager → Cinemachine → Import samples.
This is going to import a Samples folder into your project. In there, you’ll find Cinemachine → “version number” → Cinemachine Example Scenes → Scenes → FadeOutNearbyObjects.
@gaborkb Do you see it? I do not.
Can someone help? I do not see the example file as in the above screenshot…
The FadeOut sample scene is in CM 2.8. You need to update your cinemachine from 2.6.11 to 2.8.X.
@gaborkb : Right, I’ve got it now. But how do I apply this to the player and not the objects?
See this message above.
Play around with the parameters a bit, and you’ll get a feel how it works.
Issue partially solved. So I have a player. On that player is a visor. So now, the problem is that the player fades out fine, but the visor is still partially visible. When the visor becomes near-transparent, it is hard to see but it is there ( which it shouldn’t be ). Also, when I get close enough, part of the visor just blinks out of existence as you see in this short video clip. How do I fix these 2 final issues? I’ve got 1 Material for the Player itself & the same type of Material except with a white color for the children ( which could be the visor, etc ), how do i ensure the whole player object and all of its children ( despite what color they are ), fade into obscurity and when close enough, prevent part of the visor from blinking in and out of existence depending on how close or far the camera is from the player? Much thanks for your help!unsightlyhoarseairedaleterrier
You need to assign a material that fades out to all of them. You could extend our script to have more than 1 material that fades out. Or you could add a script to your player that assigns the fadeout material to all its children.
The second one is a bug in the shader. We’ll fix it.
In the meantime, you can also fix the shader:
To edit the shader, click on Edit on the material next to shader selected.
Then in the shader script, write ZWrite Off instead of ZWrite On.
Is there a URP version of this shader? It seems to only work with the standard rendering pipeline since it’s a surface shader.
We don’t have an URP version. But you could use our shader, and write one yourself :). See this for help on writing URP shader - Writing custom shaders | Universal RP | 14.0.11
Is there not an easier way to fix this transparency with the children issue? I am a programmer but I only write game-based scripts, not shaders.
Someone can help? I need a way to apply this shader to all children of an object…
I think this is what you need. Attach this to the parent gameobject, and it will assign the shader to them. Probably. Have not tested.
foreach (var material in go.GetComponentsInChildren<Material>())
{
material.shader = myShader;
}