Download

Auto Adjusting Third Person Camera In Code

Hey guys,

I am trying to set up a Dark Souls like camera in code. A video tutorial has been posted on the forum explaining it in blueprint (Can be found here). I am trying to mimic that behavior in code… but I’m stuck at around 19:30 of the video, when he finishes his initial rough version of the follow camera - it’s just not behaving right for me. This is the code:


                
                float yaw = GetControlRotation().Yaw;
		FRotator YawRotation = FRotator(0, yaw, 0);

		FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X) * GetInputAxisValue("MoveForward");
		FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y) * GetInputAxisValue("MoveRight");

		FVector movementDirection = ForwardDirection + RightDirection;

		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, movementDirection.Rotation().Euler().ToString());

		FRotator DeltaRotator = movementDirection.Rotation() - GetControlRotation();
		float deltaYaw = DeltaRotator.Yaw;
		AddControllerYawInput(deltaYaw * DeltaTime);

Anyone know what I’m doing wrong? Thanks in advance!

Bump, pretty please.