Worst-case scenario: the UEd Goblin wipes the map and burns down your house.

Legacy:Tamearia Player Opacity

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

I've seen this technique used in some games and decided it would be great to add it to Tamearia. As the camera gets close to the player, the player turns transparent.

The setup for the skins is done in the Pawn class:

class TameariaPawn extends UnrealPawn
    config(TameariaUser);
 
var ConstantColor MyColor;
var Shader MyShader, MyShader2;
var FinalBlend Skin0Final, Skin1Final;
 
...
 
simulated function PostBeginPlay()
{
    ...
 
    MyColor = New(None) class'ConstantColor';
    MyShader = New(None) class'Shader';
    MyShader2 = New(None) class'Shader';
    Skin0Final = New(None) class'FinalBlend';
    Skin1Final = New(None) class'FinalBlend';
    Skin0Final.FrameBufferBlending = FB_AlphaBlend;
    Skin1Final.FrameBufferBlending = FB_AlphaBlend;
    MyColor.Color.R = 255;
    MyColor.Color.G = 255;
    MyColor.Color.B = 255;
    MyColor.Color.A = 255;
    MyShader.Diffuse = Skins[0];
    MyShader2.Diffuse = Skins[1];
    MyShader.Opacity = MyColor;
    MyShader2.Opacity = MyColor;
    Skin0Final.Material = MyShader; // Put the Shaders into a FinalBlend to fix sorting issues.
    Skin1Final.Material = MyShader2;
    Skins[0] = Skin0Final;
    Skins[1] = Skin1Final;
 
    ...
 
}

Then, changing the opacity is done in the PlayerController class:

class TameariaController extends xPlayer
	config(TameariaUser);
 
function PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation)
{
    Super.PlayerCalcView(ViewActor,CameraLocation,CameraRotation);
    bBehindView = True;
    bFreeCamera = true;
 
    if(Pawn != none)
    {
        // Change opacity based on distance from camera.
        TameariaPawn(Pawn).MyColor.Color.A = Min(255,2 * VSize(CameraLocation - Pawn.Location));
    }
}