I'm working on a feature for a camera pawn the player can see through (it is just a third person camera). I am trying to implement a new feature that tells the camera to not change its X, Y, or Z positions but to rotate in order to track the player at any angle. I just need it to stay at a single point and track in a 360 degree rotation, like the security cameras in Deus Ex but without sweeping back and forth to track the player.
The issue is not only is the camera not rotating to follow the player if they go past it, but it is instead tracking them relative to their Z coordinates.
If I move left, the camera also moves left in a 1:1 tracking motion.
If I move right, same.
If I move toward the camera, it only changes its Z position based on how close I get to it.
If I jump, the camera jumps too.
If I run past the camera, it will still move 1:1 with my left to right movements (but mirrored because I'm behind the camera) and will adjust its Z position, but it will not rotate to face the player.
Code: Select all
var PlayerPawn LocalPlayer;
var() float CamDistance;
var float TargetDistance;
auto state Camera
{
event Tick( float DeltaTime )
{
local vector CamLoc;
local vector NewLoc;
// local rotator View;
local int OldYaw;
local int OldPitch;
if ( LocalPlayer == none )
return;
switch CameraMode
{
//=============================================================================
case CM_TrackFixed360: // The camera only tracks the player in 360 degress.
NewLoc = Location; // Location is set through a trigger, which changes the camera's state after assigning new location.
DesiredRotation = rotator( LocalPlayer.Location - Location); // Camera should track player.
SetLocation( NewLoc );
break;
//=============================================================================