How do you hide objects between the player and the camera

Im sure this has been done before. ive tried just seting the camera clipping and it did not do what i am looking for. what i want is to have an object between the camera and player to turn kind of see through so you can see what your doing. possably a script or a 2d filter?

No 2d-Filter, a 2d-Filter can only modify what is rendered.
You might rather consider a Script that casts a Ray from the Player to the Camera and if it hits an Object (or several, therefore hitObjectList) that Object could be set to Invisible or even be made transparent (though do I, right now, not know how to set an Object’s Transparency via Script – something with the MeshProxy, it seems…).

Besides: A similar Technique can also be used for Camera Collision via ray.hitPosition .

Thannks thats helpfull but i am not vary good a scripting. and im running 2.49 could someone write a script to do this?

You could try using shader nodes to fade out the transparency of certain objects when they get too close to the camera. Unfortunately, as far as I know, there is no way to pass a variable from a game to a nodes setup, so you can’t adjust the distance threshold to compensate for when the camera zooms away from the player.
If anyone knows of a way to pass a value from the game engine into a shader nodes setup, I’d really like to know it…

@ laser blaster:
There is a Way!
You simply apply a Vertex Color to the Object and in the Node Setup you then extract one of the three RGB-Values and connect it to anything. The Value can then be changed via Script.
Though I do not think that it would work that Way ‘round for somethin’ so general, that would be a Hassle. :confused:

So, what you’re saying is, you need to set the color of each vertex individually using python? That would be too slow for any complex meshes. Does anyone know of some way to change a material’s color with a python script? That seems like the way to go in this situation.

if not wrong you can use :

(but not know well the ray, you can use ray in python?)

Marco’s method would work - you should also be able to use the obj.color variable (the fourth component, in particular) to set the alpha blending level. I’m not aware of exactly the effect that will take place with several objects - I seem to remember it not working very well… Anyway, the script should be fairly simple.

SolarLune- you seem like a scripting guru. is it possable to set a plane alpha blending transparancy via script. so you can have planes turn transparent so you can see your caracter.

Here is a .blend. its a 2.49 file. can you see what i want?Boat.blend (321 KB)

I would like to help you with this, but, unfortunately, I haven’t been able to successfully change an object’s color in python. THis is what I’m using right now:

“obj.color = (0.0, 1.0, 0.0, 1.0)”

Clearly, I’m doing something wrong.
And I do have the 'ObColor ’ button ticked in the material settings. Does anyone know how to do this?

@Kylona - Huh. I thought that it was possible to do in 2.49, but apparently, per-object coloring is only available through scripting in 2.5+. Sorry about that. :frowning: Just another reason to upgrade, though. :wink:
@Laser - Are you also using Blender 2.49?

@SolarLune- I was using 2.49, but after switching over to 2.5, it’s working! Now I’m working on a setup to fade out objects the closer they get(I’ll try doing it on a per-pixel basis with material nodes).

@laser blaster - Good. I think you’ll notice that 2.5 is better in many ways when compared to 2.49. The current Texture Face to Material ability (that just kinda snuck up into the Trunk builds) is very, VERY helpful for SingleTexture (not Texture Face anymore) and Multitexture modes. I was surprised at how simple the new version is compared to the old texture face copying capability.

EDIT: Accidental dual post.

I have it pretty close to finished, the nodes setup is done, and objects now fade out as they get closer to the camera(you can adjust an RGB curves node to change the distance threshold and falloff). I have a bit more to do on the scripting side of things to make it so that only objects between the camera and player are faded, no matter the camera’s distance from the player(this functionality will only work in 2.5). I need to go to bed right now, it’s late, I’ll finish it tomorrow. Of course, if anyone wants to help out Kylona before then, feel free to do so.

I have it nearly finished: it works fine, yet it only works on one object. What I need to do is at the start of the game, loop through all of the scene’s objects, check to see if they are meshes, and if so, add them to some sort of global list that holds all of their names. Then, at each frame, I need to set the color of each object in the list to it’s desired value(which is the same for each of them). Unfortunately, I don’t know how to do any of that in python(aside from looping through all of the scenes objects, and setting an object’s color), as I’m still a beginner.

If anyone can help me do the above, then I could finish up the script.

List Help?? expert of list to come! :smiley:

I imagined that there was a problem of this kind …(list of invisibles)

however, to do list (of names?) at the start …
line 3 is 100% wrong

for i in bge.logic.getCurrentScene().objects:
     if i.mesh is 1: # <<warning
         obj["myList"].append (

not know how to make distinction, a mesh object, an object armor!

however,semm a good work laser blaster!

Thanks for helping out, MarcoIT, but I had found all the answers on my own by that point(I thought using this website to ask would be faster, I was wrong). I should have edited that post.

Anyway, the whole thing is finished now. Objects now fade out perfectly as you go behind them. The impressive thing is that even when you zoom out the camera, it compensates so that only things that are between the player and camera are made transparent. The instructions and everything are in a text document called “How to use”. You probably won’t be able to do much without those instructions(to get a a new object to use the fading effect, you need to add a property, copy the initial material a certain way, etc.). But if you don’t plan on modifying the blend file for your own purposes, you can just hit p, move with the arrow keys, and adjust the camera zoom with the W/S keys.

It requires Blender 2.5, and glsl to work. The effect will not work in multitexture or texture face modes. It will not work with 2.49. It’s not too hard to append your own characters and objects into the template and modify them to use the fade-out effect. Hopefully Kylona can make use of it, but I’ll post in in the resources forum anyway, so someone will probably find it useful.

Also, any objects that are added to the scene mid-game will not show the effect properly.

untitled.blend (585 KB)

I downloaded it right now

works perfectly! you’re too bad with your work! and I do not think there are big problems, the script is quite simple!

if I use the same material, it should be fine think …( I need just of this now)

however, it works great!