UE2 - UT2kX SetViewTarget problems

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

forrestmark9

New Member
Aug 6, 2009
56
0
0
Due to this issue being incredibly confusing I require help, basically I want to set the controllers viewtarget to a pawn if they are looking at said pawn when they are dead but currently it doesn't work, as far as I can tell SetViewTraget and ClientSetViewTarget are being called

Here is the code to get a better look
Code:
replication
{
    reliable if( Role < ROLE_Authority )
        PossessZed;
}

state Spectating
{
    function BeginState()
    {
        Super.BeginState();
        if( VSGame(Level.Game)!=None && VSGame(Level.Game).ShouldGoHunt() && !PlayerReplicationInfo.bOnlySpectator )
            GoToState('PreySpec');
    }
}

state PreySpec extends BaseSpectating
{
ignores SwitchWeapon, RestartLevel, ClientRestart, Suicide, ThrowWeapon, NotifyPhysicsVolumeChange, NotifyHeadVolumeChange;
    
    function PossessZed()
    {
        local Pawn P;
        local vector HL,HN;
        local bool bWasSpec;

        if( NextPossessTimer>Level.TimeSeconds )
            return;
        NextPossessTimer = Level.TimeSeconds+0.4f;

        foreach TraceActors(Class'Pawn',P,HL,HN,Location+vector(Rotation)*1000.f,Location)
        {
            if( P != none && P.Health>0 )
            {
                if( Monster(P)!=None )
                {
                    VSGame(Level.Game).PlayerPossess(Self,Monster(P));
                }
                else if( KFPawn(P)!=None )
                {
                    bWasSpec = !bBehindView && ViewTarget != Pawn && ViewTarget != self;
                    SetViewTarget(P);
                    ViewTargetChanged();
                    ClientSetViewTarget(P);
                    if ( ViewTarget == self || bWasSpec )
                        bBehindView = false;
                    else
                        bBehindView = true; //bChaseCam;
                    ClientSetBehindView(bBehindView);  
                }
                return;
            }
        }
        ClientMessage("Can't possess: You must aim at the specimen to possess.");
    }

    exec function Fire( optional float F )
    {
        if( NextPossessTimer<Level.TimeSeconds )
        {
            PossessZed();
            NextPossessTimer = Level.TimeSeconds+0.5f;
        }
    }
    
    exec function AltFire( optional float F )
    {
        if( ViewTarget != self )
            ServerViewSelf();
    }

    function Timer()
    {
        bFrozen = false;
    }

    function BeginState()
    {
        if ( Pawn != None )
        {
            SetLocation(Pawn.Location);
            UnPossess();
        }
        bCollideWorld = true;
        CameraDist = Default.CameraDist;
    }

    function EndState()
    {
        PlayerReplicationInfo.bIsSpectator = false;
        bCollideWorld = false;
    }
    
    function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
    {
        bBehindView = false;
        if( ViewTarget!=Self )
            SetViewTarget(Self);
        Acceleration = NewAccel;
        MoveSmooth(SpectateSpeed * Normal(Acceleration) * DeltaTime);
    }
}
 
Last edited by a moderator:

VendorX

Member
Aug 2, 2010
231
6
18
BXL/Paris
1. Put some logs around critical points to know what happens and to check if PC is in state you want to ...
2. In ProcessMove (called each tick) you have (not sure what for ...):
Code:
    function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
    {
        bBehindView = false;        [COLOR="Red"]<- switch to FP[/COLOR]
        if( ViewTarget!=Self )
            SetViewTarget(Self);        [COLOR="red"]<- ... switch to view Self[/COLOR]
        Acceleration = NewAccel;
        MoveSmooth(SpectateSpeed * Normal(Acceleration) * DeltaTime);
    }

3. Also, sometimes calling / not calling Super can have unwanted effects.
4. I think, you should consider making some changes in PlayerMove instead ...
 
Last edited: