I've been working through a tutorial where the camera view changes based on a trigger that's activated. I finally got all of my code to compile, but when I went to test the script out (created a trigger and connected it to the "top-down" node of my Kismet action), it did nothing. I'm not sure what I did wrong or how to fix it. Here's what I have (all code):
CameraGameType.uc
//--------------------------------------------------------------------------------------------------------------------
// Class Creation
//--------------------------------------------------------------------------------------------------------------------
class CameraGameType extends UTGame;
//--------------------------------------------------------------------------------------------------------------------
var int gameScore;
//---------------------------------------------------------------------------------------------------------------------
DefaultProperties
{
//Set HUD type to the Carnival HUD
HUDType=class'CameraHUD';
//Turn off classic HUD; makes ours useable
bUseClassicHUD = true;
}
CameraHUD.uc
class CameraHUD extends HUD;
//--------------------------------------------------------------------------------------------------------------------
// HUD Creation
//--------------------------------------------------------------------------------------------------------------------
//chosen font
var MultiFont CameraFont;
//--------------------------------------------------------------------------------------------------------------------
// Draw Actual HUD
//--------------------------------------------------------------------------------------------------------------------
function DrawHUD()
{
super.DrawHUD();
drawCameraScore();
}
//--------------------------------------------------------------------------------------------------------------------
// Score
//--------------------------------------------------------------------------------------------------------------------
function drawCameraScore()
{
local WorldInfo rWorldInfo;
local CameraGameType rGame;
local int CameraScore;
//populate CameraScore
//Grab Instance of WorldInfo and Verify Its Validity
rWorldInfo = class'WorldInfo'.static.GetWorldInfo();
if(WorldInfo != none)
{
//Convert Game Object to Custom Game Class
rGame = CameraGameType(rWorldInfo.Game);
//Did this work/succeed? Make sure!
if (rGame != none)
{
CameraScore = rGame.gameScore;
}
}
//Draw the score itself
//position and look
Canvas.SetPos(10,10);
Canvas.Font = MultiFont'UI_Fonts_Final.menus.Fonts_AmbexHeavyOblique';
Canvas.SetDrawColor(128,0,0);
//puts score into readable string (on screen)
Canvas.DrawText("Score:" @CameraScore);
}
DefaultProperties
{
CameraFont = MultiFont'UI_Fonts_Final.menus.Fonts_AmbexHeavyOblique';
}
CameraMovement.uc
// extend UIAction if this action should be UI Kismet Action instead of a Level Kismet Action
class CameraMovement extends SequenceAction;
//--------------------------------------------------------------------------------------------------------------------
// Player Pawn/Controller
//--------------------------------------------------------------------------------------------------------------------
var Actor ActorObj;
//--------------------------------------------------------------------------------------------------------------------
// Created Kismet Action Node
//--------------------------------------------------------------------------------------------------------------------
event Activated()
{
//top-down view
if(InputLinks[0].bHasImpulse)
{
changeCamera(1);
}
//third person view
else if(InputLinks[1].bHasImpulse)
{
changeCamera(2);
}
//isometric view
else if(InputLinks[2].bHasImpulse)
{
changeCamera(3);
}
//Side-Scrolling view
else if(InputLinks[3].bHasImpulse)
{
changeCamera(4);
}
}
//--------------------------------------------------------------------------------------------------------------------
//Camera Mode Changer
//--------------------------------------------------------------------------------------------------------------------
function changeCamera(int camID)
{
//locally declare custom variable types to capture converted generic objects
local CameraPawn rPawn;
local CameraPlayerController rController;
//ensure valid player actor was supplied to this action node through variable links
if(ActorObj != none)
{
//first try and convert attached actor variable to controller
rController = CameraPlayerController(ActorObj);
if(rController != none)
{
rPawn = CameraPawn(rController.pawn);
}
//if the actor failed to be converted to a controller or the controller's pawn = null, try to convert actor to
//custom pawn type
if(rPawn != none)
{
if(camID == 0)
{
//first-person
rPawn.CameraMode(CAM_FirstPerson);
}
else if(camID == 1)
{
//third person
rPawn.CameraMode(CAM_ThirdPerson);
}
else if(camID == 2)
{
//top-down
rPawn.CameraMode(CAM_TopDown);
}
else if(camID == 3)
{
//side-scroller
rPawn.CameraMode(CAM_SideScroller);
}
else if(camID == 4)
{
//isometric
rPawn.CameraMode(CAM_Isometric);
}
}
//Error
else
{
`log("Bad Camera ID: " @camID);
}
}
}
defaultproperties
{
ObjName="CameraMovement"
ObjCategory="PT1_Week4 Actions"
//clear input links
InputLinks.empty
InputLinks(0) = (LinkDesc="Top-Down")
InputLinks(1) = (LinkDesc="Third Person")
InputLinks(2) = (LinkDesc="Isometric")
InputLinks(3) = (LinkDesc="Side-Scroller")
//empty variable links
VariableLinks.empty
VariableLinks(0) = (ExpectedType = class 'SeqVar_Object', LinkDesc = "Player", PropertyName = "ActorObj")
//Empty Output Links So They Contain Only What We Want
OutputLinks.empty;
OutputLinks(0) = (LinkDesc = "Out")
//if true, call handler function on all targeted actors; it is set to false because our actor isn't registered
//to handle said action
bCallHandler = false
//if true, all output links will have impulse set to true
bAutoActivateOutputLinks = false
}
CameraPawn.uc (from the UDN Camera Technical Guide)
class CameraPawn extends UTPawn;
//--------------------------------------------------------------------------------------------------------------------
//All-in-One Camera
//--------------------------------------------------------------------------------------------------------------------
Enum CameraPerspective
{
CAM_FirstPerson,
CAM_ThirdPerson,
CAM_TopDown,
CAM_SideScroller,
CAM_Isometric
};
var bool bFollowPlayerRotation;
var CameraPerspective CameraType;
var float CamOffsetDistance;
var int IsoCamAngle;
exec function CameraMode(CameraPerspective mode)
{
local UTPlayerController UTPC;
CameraType = mode;
UTPC = UTPlayerController(Controller);
if (UTPC != None)
{
if(CameraType != CAM_FirstPerson)
{
UTPC.SetBehindView(true);
if(CameraType != CAM_ThirdPerson)
{
UTPC.bNoCrosshair = true;
}
else
{
UTPC.bNoCrosshair = false;
}
}
else
{
UTPC.bNoCrosshair = false;
UTPC.SetBehindView(false);
}
SetMeshVisibility(UTPC.bBehindView);
}
}
exec function IsoAngle(int angle)
{
IsoCamAngle = angle;
}
/* BecomeViewTarget
Called by Camera when this actor becomes its ViewTarget */
simulated event BecomeViewTarget( PlayerController PC )
{
local UTPlayerController UTPC;
Super.BecomeViewTarget(PC);
if (LocalPlayer(PC.Player) != None)
{
UTPC = UTPlayerController(PC);
if (UTPC != None)
{
if(CameraType != CAM_FirstPerson)
{
UTPC.SetBehindView(true);
if(CameraType != CAM_ThirdPerson)
{
UTPC.bNoCrosshair = true;
}
else
{
UTPC.bNoCrosshair = false;
}
}
else
{
UTPC.bNoCrosshair = false;
UTPC.SetBehindView(false);
}
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 (bFixedView)
{
out_CamLoc = FixedViewLoc;
out_CamRot = FixedViewRot;
}
else
{
if ( CameraType == CAM_ThirdPerson ) // Handle BehindView
{
CalcThirdPersonCam(fDeltaTime, out_CamLoc, out_CamRot, out_FOV);
}
else if ( CameraType == CAM_TopDown ) // Handle BehindView
{
CalcTopDownCam(fDeltaTime, out_CamLoc, out_CamRot, out_FOV);
}
else if ( CameraType == CAM_SideScroller ) // Handle BehindView
{
CalcSideScrollerCam(fDeltaTime, out_CamLoc, out_CamRot, out_FOV);
}
else if ( CameraType == CAM_Isometric ) // Handle BehindView
{
CalcIsometricCam(fDeltaTime, out_CamLoc, out_CamRot, out_FOV);
}
else
{
// By default, we view through the Pawn's eyes..
GetActorEyesViewPoint( out_CamLoc, out_CamRot );
}
if ( UTWeapon(Weapon) != none)
{
UTWeapon(Weapon).WeaponCalcCamera(fDeltaTime, out_CamLoc, out_CamRot);
}
}
return true;
}
simulated function bool CalcTopDownCam( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
{
out_CamLoc = Location;
out_CamLoc.Z += CamOffsetDistance;
if(!bFollowPlayerRotation)
{
out_CamRot.Pitch = -16384;
out_CamRot.Yaw = 0;
out_CamRot.Roll = 0;
}
else
{
out_CamRot.Pitch = -16384;
out_CamRot.Yaw = Rotation.Yaw;
out_CamRot.Roll = 0;
}
return true;
}
simulated function bool CalcSideScrollerCam( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
{
out_CamLoc = Location;
out_CamLoc.Y = CamOffsetDistance;
out_CamRot.Pitch = 0;
out_CamRot.Yaw = 16384;
out_CamRot.Roll = 0;
return true;
}
simulated function bool CalcIsometricCam( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
{
out_CamLoc = Location;
out_CamLoc.X -= Cos(IsoCamAngle * UnrRotToRad) * CamOffsetDistance;
out_CamLoc.Z += Sin(IsoCamAngle * UnrRotToRad) * CamOffsetDistance;
out_CamRot.Pitch = -1 * IsoCamAngle;
out_CamRot.Yaw = 0;
out_CamRot.Roll = 0;
return true;
}
/**
* returns base Aim Rotation without any adjustment (no aim error, no autolock, no adhesion.. just clean initial aim rotation!)
*
* @return base Aim rotation.
*/
simulated singular event Rotator GetBaseAimRotation()
{
local vector POVLoc;
local rotator POVRot, tempRot;
if(CameraType == CAM_TopDown || CameraType == CAM_Isometric)
{
tempRot = Rotation;
tempRot.Pitch = 0;
SetRotation(tempRot);
POVRot = Rotation;
POVRot.Pitch = 0;
}
else if(CameraType == CAM_SideScroller)
{
POVRot = Rotation;
if( (Rotation.Yaw % 65535 > 16384 && Rotation.Yaw % 65535 < 49560) ||
(Rotation.Yaw % 65535 < -16384 && Rotation.Yaw % 65535 > -49560) )
{
POVRot.Yaw = 32768;
}
else
{
POVRot.Yaw = 0;
}
if( POVRot.Pitch == 0 )
{
POVRot.Pitch = RemoteViewPitch << 8;
}
}
else
{
if( Controller != None && !InFreeCam() )
{
Controller.GetPlayerViewPoint(POVLoc, POVRot);
return POVRot;
}
else
{
POVRot = Rotation;
if( POVRot.Pitch == 0 )
{
POVRot.Pitch = RemoteViewPitch << 8;
}
}
}
return POVRot;
}
DefaultProperties
{
CameraType=CAM_FirstPerson;
bFollowPlayerRotation = false;
CamOffsetDistance=384.0
IsoCamAngle=6420 //35.264 degrees
}
CameraPlayerController.uc (from the UDN Camera Technical Guide)
class CameraPlayerController extends UTPlayerController;
//--------------------------------------------------------------------------------------------------------------------
//All-in-One Camera
//--------------------------------------------------------------------------------------------------------------------
state PlayerWalking
{
function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
{
local CameraPawn P;
local Rotator tempRot;
if( (Pawn != None) )
{
P = CameraPawn(Pawn);
if(P != none)
{
if(P.CameraType == CAM_SideScroller)
{
Pawn.Acceleration.X = -1 * PlayerInput.aStrafe * DeltaTime * 100 * PlayerInput.MoveForwardSpeed;
Pawn.Acceleration.Y = 0;
Pawn.Acceleration.Z = 0;
tempRot.Pitch = P.Rotation.Pitch;
tempRot.Roll = 0;
if(Normal(Pawn.Acceleration) Dot Vect(1,0,0) > 0)
{
tempRot.Yaw = 0;
P.SetRotation(tempRot);
}
else if(Normal(Pawn.Acceleration) Dot Vect(1,0,0) < 0)
{
tempRot.Yaw = 32768;
P.SetRotation(tempRot);
}
}
else
{
if ( (DoubleClickMove == DCLICK_Active) && (Pawn.Physics == PHYS_Falling) )
DoubleClickDir = DCLICK_Active;
else if ( (DoubleClickMove != DCLICK_None) && (DoubleClickMove < DCLICK_Active) )
{
if ( UTPawn(Pawn).Dodge(DoubleClickMove) )
DoubleClickDir = DCLICK_Active;
}
Pawn.Acceleration = newAccel;
}
if (Role == ROLE_Authority)
{
// Update ViewPitch for remote clients
Pawn.SetRemoteViewPitch( Rotation.Pitch );
}
}
CheckJumpOrDuck();
}
}
}
function UpdateRotation( float DeltaTime )
{
local CameraPawn P;
local Rotator DeltaRot, newRotation, ViewRotation;
P = CameraPawn(Pawn);
ViewRotation = Rotation;
if (p != none && P.CameraType != CAM_SideScroller)
{
Pawn.SetDesiredRotation(ViewRotation);
}
// Calculate Delta to be applied on ViewRotation
if( P != none && P.CameraType == CAM_SideScroller )
{
DeltaRot.Yaw = Pawn.Rotation.Yaw;
}
else
{
DeltaRot.Yaw = PlayerInput.aTurn;
}
DeltaRot.Pitch = PlayerInput.aLookUp;
ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
SetRotation(ViewRotation);
ViewShake( deltaTime );
NewRotation = ViewRotation;
NewRotation.Roll = Rotation.Roll;
if (P != None && P.CameraType != CAM_SideScroller )
Pawn.FaceRotation(NewRotation, deltatime);
}
DefaultProperties
{
}
My Trigger:
Kismet:
I was so close too! Help would be awesome right about now. ^^;; Thank you!
Replies
For me this is littering my scripts with logs. everywhere.
Every function has a log telling me that function is running. Every if/else etc has a log telling me which one is running through. Every bool has a log telling me when they're changing and what they're changing to. etc. etc.
If you haven't already, create a shortcut for UDK, right click and go to properties. Where the target is add "-log"
(would look like this: C:\UDK\UDK-2012-05\Binaries\UDKLift.exe editor -log)
When you launch that shortcut, it will now have a black log window open along with the editor.
Now everywhere you have a log in script getting called - it's going to show there. Same with any kismet logs.
Now in the play in editor I can see exactly what's going on. which function are being called that shouldn't be. Which ones should be called, but aren't. etc. etc.
I also use 'PotBeginPlay' event in quite a few of my scripts. Looks like this in my pawn:
simulated event PostBeginPlay()
{
super.PostBeginPlay();
`log("my custom pawn is alive");
}
Now when my pawn spawns, I know its my pawn (from the log) - not ut.
If you had this in both your pawn, and playercontroller, you would see in your log window that neither of them are being used.
Why aren't they being used? What part of the scripts is supose to set your pawn, and pc? Your gameInfo/gametype. You haven't set your 'CameraGameType' to use either your pawn, or PC.
Two bugs down, maybe more bugs to go?
I just follow that process. Look at the logs, see what's going on that shouldn't be, go back to the scripts and see why and where things are going wrong.
Hope that helps