TPP Camera - Adding offsets

Based on this tutorial:

I reimplemented very basic and simple TPP Camera.:

void ATPPPlayerCamera::UpdateViewTarget(FTViewTarget& OutVT, float DeltaTime)
{
	FVector Loc, Pos, HitLocation, HitNormal;
	FRotator Rot;
	FPOV OrigPOV;
	FMath math = FMath();
	OrigPOV = OutVT.POV;
	
	Loc = OutVT.Target->GetActorLocation();
	Rot = OutVT.Target->GetActorRotation();
	Rot = PCOwner->GetActorRotation();
	FVector RotToVec;
	RotToVec = Rot.Vector();
	Pos = Loc - RotToVec;
	FVector Offset;
	Offset = FVector(-400.0f, 0.0f, 20.0f);
	Pos.Y += -100.0f;// * (-Rot.Yaw * PI * 2/65536);
	Pos.Z +=  50.0f;// * (Rot.Yaw * PI * 2/65536);

	OutVT.POV.Location = Pos;
	OutVT.POV.Rotation = Rot;
}

Pos.Y += 100.0f etc, should provide offset to camera, but of course there is an issue that makes camera do not stick to character back while rotating. The letter part of the same line should fix it, but this screw my offsets (as you may imagine the are just fraction of what they should be) and never the less the camera is still choppy (it jumps from one position to another while rotating).

Hi Lukasz,

It appears you are setting Rot twice in a row.

Rot = OutVT.Target->GetActorRotation();
Rot = PCOwner->GetActorRotation();

I do not believe that was intended. Let me know if that was the cause.

-Alexander

It was ( thought the next value just override previous) but in any case removing any of the lines doesn’t change anything. Removing OutVT, changes nothing, and removing PCOwner causes camera to do not pitch.

How did you declare the UpdateViewTarget function in the header file? Was it protected, a virtual void?

public and virtual void.

it doesnt seem to work. Can you show me your header class for the camera

it says unresolved external symbol public virtual void UpdateViewTarget FTViewTarget&, float

#include “RPGPlayerCamera.generated.h”

UCLASS(config=Game)
class ARPGPlayerCamera : public APlayerCamera
{
	GENERATED_UCLASS_BODY()
public:
	//virtual void UpdateCamera(float DeltaTime) OVERRIDE;
	virtual void UpdateViewTarget(FTViewTarget& OutVT, float DeltaTime) OVERRIDE;
};

Nothing really complicated.

I think you made it too complicated. For Pos it should equal to loc-rottovec*offset
im assuming rottovec is the rotation in vector, correct?

Oh and delete Pos.Y and Pos.Z and rather put those values in the offset.

I did it like this:
FinalPos += FRotationMatrix(Rot).TransformVector(FinalOffset);
And It’s working now.

There you go. =)

I solved it. Here is code if anyone is intresed:

FVector Loc, Pos, HitLocation, HitNormal, EyeLoc, FinalPos;
FRotator Rot, EyeRot;
FPOV OrigPOV;
FMath math = FMath();

//It should be header file, but for now it will work.
FVector LowOffset = FVector(-100.0f,0,20.0f);
FVector MidOffset = FVector(-100.0f,0,20.0f);
FVector HighOffset = FVector(-50.0f,0,100.0f);

FVector FinalOffset = MidOffset;

OrigPOV = OutVT.POV;
OutVT.Target->GetActorEyesViewPoint(EyeLoc, EyeRot);
Loc = OutVT.Target->GetActorLocation();

DrawDebugString(FVector(0,0,0), EyeRot.ToString());
FVector const Offset = FVector(-150.0f, 0.0f, 0.0f);
FinalPos = EyeLoc;
FinalPos += FRotationMatrix(EyeRot).TransformVector(FinalOffset);

OutVT.POV.Location = FinalPos;
OutVT.POV.Rotation = EyeRot;