How to make object transparented when player approaches them based on their distance?
1. In your material active (enable, check) Transparency checkbox:



2. Select the desire object

3. In logic editor, add an always sensor connected to a pyton controller:


4. script.py

from bge import logic
own = logic.getCurrentController().owner
player = logic.getCurrentScene().objects['Cube']
distance = own.getDistanceTo(player)
#if distance 
print('distance : ', distance*0.02)
if distance * 0.04 &lt; 1:
    own.meshes[0].materials[0].alpha = distance * 0.04
    print('alpha : ', own.meshes[0].materials[0].alpha)


Related

Python API (bge object material)

bge.types.KX_BlenderMaterial.alpha