当前位置: 首页 > article >正文

UE4 C++创建摄像机摇臂和相机并且设置Transform

新建MyPawn C++类

.h

#include "GameFramework/SpringArmComponent.h"	//SpringArm组件
#include "Camera/CameraComponent.h"	//Camera组件

class 工程名称_API AMyPawn : public APawn
{
//定义组件变量
public:
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "MySceneComponent");
		USceneComponent* MyRoot;
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "MySceneComponent");
		USpringArmComponent* MySpringArm;
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "MySceneComponent");
		UCameraComponent* MyCamera;
}

.cpp

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

	//初始化组件变量的值
	MyRoot = CreateDefaultSubobject<USceneComponent>(TEXT("MyRoot"));
	MySpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("MySprintArm"));
	MyCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("MyCamera"));

	//设置父子层级关系
	RootComponent = MyRoot;
	MySpringArm->SetupAttachment(MyRoot);
	MyCamera->SetupAttachment(MySpringArm);
	MySpringArm->bDoCollisionTest = false;	//关闭DoCollisionTest
}

void AMyPawn::BeginPlay()
{
	Super::BeginPlay();

	//设置MyPawn的Transform
	FVector MyLocation = FVector(0,0,0);
	FRotator MyRotation = FRotator(-50,0,0);
	FVector MyScale = FVector(1,1,1);
	SetActorLocation(MyLocation);
	SetActorRotation(MyRotation);
	SetActorScale3D(MyScale);
}

运行后
在这里插入图片描述


http://www.kler.cn/a/231067.html

相关文章:

  • 本地缓存Ehcache的应用实践 | 京东云技术团队
  • SpringBoot过滤器获取请求的参数
  • 使用Python实现简单的文本分类器
  • Spring Boot RestTemplate请求证书问题
  • 原码反码补码、浮点数
  • vio参数文件内相机imu参数的修改
  • 51单片机 跑马灯
  • 1971 - 大小写转换
  • 机器学习与深度学习
  • 微服务的幂等性
  • 开关电源学习之Boost电路
  • 幻兽帕鲁客户端存档文件 - 云上备份和恢复教程
  • 【WPF】布局容器/面板总结XAML-Panel控件
  • 【Git教程】(一)基本概念 ——工作流、分布式版本控制、版本库 ~
  • Vue2.6+Echarts+Bmap构建地图
  • Mongodb启动为Windows服务开机自启动
  • 数据结构之归并排序
  • 【自动化测试】---Selenium+Java
  • RabbitMQ-4.MQ的可靠性
  • 微信小程序(三十六)事件传参