UE5学习笔记3-关于charactor的相机和弹簧臂组件

一、环境说明,UE5.4 + vs2022 + win11

二、相机和弹簧臂的作用

        个人理解上,相机的作用相当于一个视角,我将其理解成是一个人在哪个地方朝向哪个方向看,弹簧臂的用用我将其理解成为一个将人的视角和人物模型或其他模型连接的桥梁

三、相机和弹簧臂的代码

        xxx.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "BlasterCharacter.generated.h"

UCLASS()
class BLASTER_API ABlasterCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	ABlasterCharacter();	
	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

private:
	/** 弹簧臂组件类声明 属性设置为在任何地方可视 类别是摄像机 */
	UPROPERTY(VisibleAnywhere, Category = Camera)
	class USpringArmComponent* CameraBoom;

	/** 摄像机类声明 属性设置为在任何地方可视 类别是摄像机 */
	UPROPERTY(VisibleAnywhere, Category = Camera)
	class UCameraComponent* FollowCamera;
public:	

};

        xxx.cpp 

// Fill out your copyright notice in the Description page of Project Settings.


#include "BlasterCharacter.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"

// Sets default values
ABlasterCharacter::ABlasterCharacter()
{
 	// Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));/** 创建类 */
	CameraBoom->SetupAttachment(GetMesh());/** SetupAttachment()将弹簧臂固定在网格上 GetMesh()获得角色的网格(胶囊体) */
	CameraBoom->TargetArmLength = 600.f;/** 设置臂长 */
	CameraBoom->bUsePawnControlRotation = true;/** 是否控制旋转 */

	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	/** 设置附件 将摄像机连接到弹簧臂上,通过USpringArmComponent的指针和USpringArmComponent的名字USpringArmComponent::SocketName*/
	FollowCamera->SetupAttachment(CameraBoom,USpringArmComponent::SocketName);
	/** 跟随摄像头无需使用旋转 旋转在CameraBoom  CameraBoom是FollowCamera的组件 */
	FollowCamera->bUsePawnControlRotation = false;
}

// Called every frame
void ABlasterCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
}


// Called when the game starts or when spawned
void ABlasterCharacter::BeginPlay()
{
	Super::BeginPlay();
	
}

 四、效果展示

        打开刚才创建的蓝图选择右面的CameraBoom,在没选择之前只会看见一个摄像机,选中后可以看见摄像机和人物之间有一条红线,红线就是弹簧臂,可以将代码中有关弹簧臂的代码注释掉在打开蓝图观察。刚开始时摄像机会在地面上,找到右面的细节界面将变换中的位置中的Z改成98或则其他数值,点击编译,点击保存

        在UE5的界面中点击绿色箭头运行实例效果如图所示,角色头上的字母是之后的东西,当前的地图可以在epic launch中的虚幻商城中搜索虚幻嘘唏工具包找到对用的地图资源

 

 五、补充说明,将人物放到场景中

        点击人物的蓝图类拖动到地图资源界面中松开鼠标后人物添加到对应位置

        1.拖动前

        2.拖动中

        3.拖动后

        4.保存 

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值