|
In certain games, there is a function involved where if there is an object between the camera's view and the player, the object will either become transparent, or the player's silhouette is visible on the object. Would I need some sort of custom diffuse shader, or is there a function that will allow me to change the visibility of an object. Also, how would I do a raycast/vector check to determine if the object is between the player and camera. Would I need Pro for the transparency part?
(comments are locked)
|
|
Just do it like Jean said. The Unity script reference on RaycastAll gives you an example for exact your case except it does not revert the transparency. A list would be a solution, but it gets tricky to determine what renderers have to be reverted, which ones should stay transparent and which ones have to set transparent. I would write a little script that you can attach dynamically to those renderes which should be transparent. In that script you can implement some kind of falloff and when it'sno longer needed it removes itself. C#: Here's an example script that gets dynamically attached to the renderer and the script that do the raycast.
//And here the script for the camera to cast the ray / capsule ;
The two script files need to be named like the class names (AutoTransparent and ClearSight). edit I guess your camera script is also on the camera like my ClearSight script. JS:
But don't forget: you need the distance in units. If you have the distance already, great, just pass it to my script ;) initially i just want to write a small example script but i ended up with a full example :D. But: it's not testet yet. Syntax should be right (at least Visual C# Express can't find errors)
Jan 27 '11 at 08:25 AM
Bunny83
Cool, thanks! I will try this when I get to my work desk!
Jan 27 '11 at 07:35 PM
SirVictory
Okay, so I attached this script to the object I wanted to become transparent. When you run the game, the object's alpha gradually changes (without the camera even viewing the object) then the object's shader becomes null.
Jan 27 '11 at 10:04 PM
SirVictory
or am I suppose to do something additional in conjunction with this script?
Jan 27 '11 at 10:06 PM
SirVictory
That's funny, in our hack and slash game i also created a avoid-collision-camera by zooming in. Now that i wrote that little script for you i will implement that on top because at some places where little object are in the way the camera zooms in and out all the time. I imagine such a function long ago, but there was no need for, until now ;)
Jan 28 '11 at 04:09 AM
Bunny83
(comments are locked)
|
|
Hi SirVictory, Raycasting would be a start, that is, you raycast from the player position and whatever is hit before the player should be send a message or dealt in some way to become semi transparent. you would need to maintain a list so that you can toggle semi transparent models back when not anymore in front of the player, Else, you could actually have a box collider starting from the player and pointing at the camera where its size emcopass the player bounds, then anything that collides to that are also in the way. Otherwise, Physics.CapsuleCast could be also an alternative to building a collider, but very similar in principle, tho the start point would need to be sligtly tweacked and not start right where the player is but slightly closer to the camera to not hit the ground or things to close to the player. As for the shader, I would replace it with a specific simple one while in front, you might want to have front and backface material for object very close to the camera. Hope it helps, Jean
(comments are locked)
|
|
I've implemented the same script posted by Bunny83. Mine is in JavaScript and it changes the transparency gradually.
Here's how you can use it:
Hope somebody finds this useful. Thank you. This script worked perfect right out of the box. It's exactly what I was looking for. I really look forward to deconstructing your code. I use this code to call the transparent class and it seems perfect for what i'm needing. var hit : RaycastHit; if (Physics.Linecast(target.position, transform.position, hit)) { var currentRenderer = hit.transform.gameObject.renderer; //Make transparent if (currentRenderer) { var autoTransparent : AutoTransparent = currentRenderer.GetComponent("AutoTransparent"); }
Jul 23 '11 at 02:49 AM
Cymrix
(comments are locked)
|
|
Silly question.
(comments are locked)
|

Oh i forgot: you don't need Pro for enything like that ;) have fun