UEC++创建摄像机摇臂和相机并且设置位置旋转位移缩放(UEC++个人学习笔记)

在.h文件添加头文件,弹簧臂组件和相机组件

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

 然后声明组件

public:
		//场景组件,作为根主键
		UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "MySceneComponent")
			USceneComponent* MyRoot;
		//摄像机摇臂组件
		UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "MySceneComponent")
			USpringArmComponent* MySpringArm;
        //相机组件
		UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "MySceneComponent")
			UCameraComponent* MyCamera;

 在cpp文件中,定义了三个函数,根,弹簧臂,相机

    MyRoot = CreateDefaultSubobject<USceneComponent>(TEXT("MyRootComponent"));
	MySpringArm = CreateDefaultSubobject<USpringArmComponent(TEXT("MySpringArmComponent"));
	MyCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("MySCameraComponent"));
	

 

设置父子关系,将摇杆臂放在根组件下,然后将相机放在摇杆臂里面

    RootComponent = MyRoot;
	MySpringArm->SetupAttachment(MyRoot);
	//将相机放在摄像机摇臂组件下
	MyCamera->SetupAttachment(MySpringArm);
    //设置碰撞,设置为false
	MySpringArm->bDoCollisionTest=false;

像这样

然后在beginpaly设置位置

//设置位置
	FVector MyLocation = FVector(0, 0, 0);

	//设置旋转
	FRotator MyRotation = FRotator(-50, 0, 0);

	//设置缩放
	FVector MyScale = FVector(1, 1, 1);

	SetActorLocation(MyLocation);
	SetActorRotation(MyRotation);
	SetActorScale3D(MyScale);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值