He's got it backwards. :-)
Use this.
X2 should be the distance at which you want the entity to be opaque, and X1 should be the distance at which you want it to be transparent. Median# is the current distance of the object from the camera. You can use the EntityDistance function to get this. Or use D# = Sqr((X1#-X2#)^2 + (Y1#-Y2#)^2 + (Z1#-Z2#)^2)
Then take the number that comes out of this function, and if it is greater than 1, set it to 1. And if it is less than 0, set it to 0.
Calculate this value every frame, and set the entity's alpha to it. Then your entity will fade in as it approaches the camera.
; ------------------------------------------------------------------------------------------------------------------- ; This function allows you to do the reverse of a linear interpolation between two values. ; ; Instead of specifying the tween value, you specify the value which you want the know the tween of. ; ; Essentially, this function will tell you where a value is between two other values. If the value is between ; the two values, then the result will be in the range of 0..1. ; ------------------------------------------------------------------------------------------------------------------- Function AniBOB_InverseTween#(X1#, X2#, Median#) ; If the difference between x1 and x2 is 0, then there is no tween value which will give you the value of ; median, unless median is equal to x1 or x2, in which case all tween values will give you the correct result. ; So we just return 0 for the tweening value if the difference is 0. If (X2# - X1#) <> 0 Return (Median# - X1#) / (X2# - X1#) Else Return 0 EndIf End Function
Use this.
X2 should be the distance at which you want the entity to be opaque, and X1 should be the distance at which you want it to be transparent. Median# is the current distance of the object from the camera. You can use the EntityDistance function to get this. Or use D# = Sqr((X1#-X2#)^2 + (Y1#-Y2#)^2 + (Z1#-Z2#)^2)
Then take the number that comes out of this function, and if it is greater than 1, set it to 1. And if it is less than 0, set it to 0.
Calculate this value every frame, and set the entity's alpha to it. Then your entity will fade in as it approaches the camera.