RPG2.设置角色摄像机
为了能在debug中方便输出一些打印信息,创建一个空白的c++类文件,我是用的是RIDER,直接在public内进行类创建即可。
1.创建debugHelper
2.在debughelper内创建一个命名空间namespace
namespace Debug
{static void Print(const FString& Msg, const FColor& Color = FColor::MakeRandomColor(), int32 InKey = -1){if (GEngine){GEngine->AddOnScreenDebugMessage(InKey, 5.f, Color, Msg);UE_LOG(LogTemp, Warning, TEXT("%s"), *Msg);}}
}
3.在玩家类里重写beginplay,在beginplay内进行debughelper的函数使用
4.运行游戏,打开日志
出现logtemp,说明debughelper使用成功。可以使用debughelper用以测试。
5.创建角色摄像机
摄像机
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true"))UCameraComponent* FollowCamera;
弹簧臂
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true"))USpringArmComponent* CameraBoom;
接着在玩家角色内创建构造函数,在构造函数内实现创建组件
#include "Character/XMBCharacter.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/CharacterMovementComponent.h"#include "XMBDebugHelper.h"AXMBCharacter::AXMBCharacter()
{GetCapsuleComponent()->InitCapsuleSize(42.f, 96.f);bUseControllerRotationPitch = false;bUseControllerRotationYaw = false;bUseControllerRotationRoll = false;CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));CameraBoom->SetupAttachment(GetRootComponent());CameraBoom->TargetArmLength = 300.0f;CameraBoom->SocketOffset = FVector(0.0f, 55.0f, 60.0f);CameraBoom->bUsePawnControlRotation = true;FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);FollowCamera->bUsePawnControlRotation = false;GetCharacterMovement()->bOrientRotationToMovement = true;GetCharacterMovement()->RotationRate = FRotator(0.0f, 550.0f, 0.0f);GetCharacterMovement()->MaxWalkSpeed = 400.f;GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;}
6.打开项目,见此则成功
7.设置骨骼