Code:
Enum AimPerspective
{
AIM_Normal,
AIM_OverShoulder
};
var bool bFollowPlayerRotation;
var AimPerspective AimType;
exec function AimingMode(AimPerspective mode)
{
local SICPlayerController UTPC;
AimType = mode;
UTPC = SICPlayerController(Controller);
if (UTPC != None)
{
UTPC.SetBehindView(true);
SetMeshVisibility(UTPC.bBehindView);
}
}
/* BecomeViewTarget
Called by Camera when this actor becomes its ViewTarget */
simulated event BecomeViewTarget( PlayerController PC )
{
local SICPlayerController UTPC;
Super.BecomeViewTarget(PC);
if (LocalPlayer(PC.Player) != None)
{
UTPC = SICPlayerController(PC);
if (UTPC != None)
{
UTPC.SetBehindView(true);
SetMeshVisibility(UTPC.bBehindView);
}
}
}
/**
* Calculate camera view point, when viewing this pawn.
*
* @param fDeltaTime delta time seconds since last update
* @param out_CamLoc Camera Location
* @param out_CamRot Camera Rotation
* @param out_FOV Field of View
*
* @return true if Pawn should provide the camera point of view.
*/
simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
{
// Handle the fixed camera
if ( AimType == AIM_Normal ) // Handle BehindView
{
CalcNormalCam(fDeltaTime, out_CamLoc, out_CamRot, out_FOV);
}
else if ( AimType == AIM_OverShoulder ) // Handle BehindView
{
CalcOverShoulderCam(fDeltaTime, out_CamLoc, out_CamRot, out_FOV);
}
return true;
}
simulated function bool CalcNormalCam( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
{
local vector CamStart, HitLocation, HitNormal, CamDirX, CamDirY, CamDirZ, CurrentCamOffset;
local float DesiredCameraZOffset;
CamStart = Location;
CurrentCamOffset = CamOffset;
CurrentCamOffset.X += CameraDistance;
DesiredCameraZOffset = (Health > 0) ? 1.2 * GetCollisionHeight() + Mesh.Translation.Z - 2 : 0.f;
CameraZOffset = (fDeltaTime < 0.2) ? DesiredCameraZOffset * 5 * fDeltaTime + (1 - 5*fDeltaTime) * CameraZOffset : DesiredCameraZOffset;
if ( Health <= 0 )
{
CurrentCamOffset = vect(0,0,0);
CurrentCamOffset.X = GetCollisionRadius();
}
CamStart.Z += CameraZOffset;
GetAxes(out_CamRot, CamDirX, CamDirY, CamDirZ);
CamDirX *= CurrentCameraScale;
if ( (Health <= 0) || bFeigningDeath )
{
// adjust camera position to make sure it's not clipping into world
// @todo fixmesteve. Note that you can still get clipping if FindSpot fails (happens rarely)
FindSpot(GetCollisionExtent(),CamStart);
}
if (CurrentCameraScale < CameraScale)
{
CurrentCameraScale = FMin(CameraScale, CurrentCameraScale + 5 * FMax(CameraScale - CurrentCameraScale, 0.3)*fDeltaTime);
}
else if (CurrentCameraScale > CameraScale)
{
CurrentCameraScale = FMax(CameraScale, CurrentCameraScale - 5 * FMax(CameraScale - CurrentCameraScale, 0.3)*fDeltaTime);
}
if (CamDirX.Z > GetCollisionHeight())
{
CamDirX *= square(cos(out_CamRot.Pitch * 0.0000958738)); // 0.0000958738 = 2*PI/65536
}
out_CamLoc = CamStart - CamDirX*CurrentCamOffset.X + CurrentCamOffset.Y*CamDirY + CurrentCamOffset.Z*CamDirZ;
if (Trace(HitLocation, HitNormal, out_CamLoc, CamStart, false, vect(12,12,12)) != None)
{
out_CamLoc = HitLocation;
}
return true;
}
simulated function bool CalcOverShoulderCam( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
{
local vector CamStart, HitLocation, HitNormal, CamDirX, CamDirY, CamDirZ, CurrentCamOffset;
local float DesiredCameraZOffset;
CamStart = Location;
CurrentCamOffset = CamOffset;
DesiredCameraZOffset = (Health > 0) ? 1.2 * GetCollisionHeight() + Mesh.Translation.Z - 2 : 0.f;
CameraZOffset = (fDeltaTime < 0.2) ? DesiredCameraZOffset * 5 * fDeltaTime + (1 - 5*fDeltaTime) * CameraZOffset : DesiredCameraZOffset;
if ( Health <= 0 )
{
CurrentCamOffset = vect(0,0,0);
CurrentCamOffset.X = GetCollisionRadius();
}
CamStart.Z += CameraZOffset;
GetAxes(out_CamRot, CamDirX, CamDirY, CamDirZ);
CamDirX *= CurrentCameraScale;
if ( (Health <= 0) || bFeigningDeath )
{
// adjust camera position to make sure it's not clipping into world
// @todo fixmesteve. Note that you can still get clipping if FindSpot fails (happens rarely)
FindSpot(GetCollisionExtent(),CamStart);
}
if (CurrentCameraScale < CameraScale)
{
CurrentCameraScale = FMin(CameraScale, CurrentCameraScale + 5 * FMax(CameraScale - CurrentCameraScale, 0.3)*fDeltaTime);
}
else if (CurrentCameraScale > CameraScale)
{
CurrentCameraScale = FMax(CameraScale, CurrentCameraScale - 5 * FMax(CameraScale - CurrentCameraScale, 0.3)*fDeltaTime);
}
if (CamDirX.Z > GetCollisionHeight())
{
CamDirX *= square(cos(out_CamRot.Pitch * 0.0000958738)); // 0.0000958738 = 2*PI/65536
}
out_CamLoc = CamStart - CamDirX*CurrentCamOffset.X + CurrentCamOffset.Y*CamDirY + CurrentCamOffset.Z*CamDirZ;
if (Trace(HitLocation, HitNormal, out_CamLoc, CamStart, false, vect(12,12,12)) != None)
{
out_CamLoc = HitLocation;
}
return true;
}
defaultproperties
{
AimType=AIM_Normal;
CameraDistance = 17;
}
MyCustomPlayerController.uc
Code:
state PlayerWalking
{
function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
{
local SICPawn P;
// local Rotator tempRot;
if( (P != None) )
{
P = SICPawn(Pawn);
}
if (Role == ROLE_Authority)
{
// Update ViewPitch for remote clients
Pawn.SetRemoteViewPitch( Rotation.Pitch );
}
Pawn.Acceleration = NewAccel;
CheckJumpOrDuck();
}
}
function UpdateRotation( float DeltaTime )
{
local Rotator DeltaRot, newRotation, ViewRotation;
local SICPawn P;
P = SICPawn(Pawn);
ViewRotation = Rotation;
if (p != none)
{
P.SetDesiredRotation(ViewRotation);
}
// Calculate Delta to be applied on ViewRotation
DeltaRot.Yaw = PlayerInput.aTurn;
DeltaRot.Pitch = PlayerInput.aLookUp;
ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
SetRotation(ViewRotation);
NewRotation = ViewRotation;
NewRotation.Roll = Rotation.Roll;
if ( P != None )
P.FaceRotation(NewRotation, deltatime);
ViewShake( deltaTime );
}
defaultproperties
{
}
I've looked tightly into this situation and found no reason that there should be ever a problem. I am using January 2012 UDK version, however unlikely this KeyBinding issue would to be the blame for the January version. If anyone had have some insight - be kind to share. This is puzzling more than a rubic's cube.
Bookmarks