当前位置:网站首页>U++学习笔记 基础人物轴绑定及映射绑定
U++学习笔记 基础人物轴绑定及映射绑定
2022-07-23 21:42:00 【是秃头的兔子呀】
PawnWithCamera.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "PawnWithCamera.generated.h"
UCLASS()
class FLOATINGCUBE_API APawnWithCamera : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
APawnWithCamera();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere)
class USpringArmComponent* SpringArmComp;
UPROPERTY(EditAnywhere)
class UCameraComponent* CameraComp;
UPROPERTY(EditAnywhere)
class UStaticMeshComponent* StaticMeshComp;
FVector2D MovementInput;
FVector2D CameraInput;
float ZoomFactor;
bool bZoomingIn;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
void MoveForward(float AxisValue);
void MoveRight(float AxisValue);
void PitchCamera(float AxisValue);
void YawCamera(float AxisValue);
void ZoomIn();
void ZoomOut();
};
PawnWithCamera.cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "PawnWithCamera.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "FloatingCube.h"
// Sets default values
APawnWithCamera::APawnWithCamera()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootSceneComponent"));
StaticMeshComp = CreateDefaultSubobject <UStaticMeshComponent>(TEXT("StaticMeshComponent"));
SpringArmComp = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComponent"));
CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
//Attach our components
StaticMeshComp->SetupAttachment(RootComponent);
SpringArmComp->SetupAttachment(StaticMeshComp);
CameraComp->SetupAttachment(SpringArmComp, USpringArmComponent::SocketName);
//Assign SpringArm class variables.
SpringArmComp->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, 50.0f), FRotator(-60.0f, 0.0f, 0.0f));
SpringArmComp->TargetArmLength = 400.f;
SpringArmComp->bEnableCameraLag = true;
SpringArmComp->CameraLagSpeed = 3.0f;
//Take control of the default Player
AutoPossessPlayer = EAutoReceiveInput::Player0;
}
// Called when the game starts or when spawned
void APawnWithCamera::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void APawnWithCamera::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (bZoomingIn) {
ZoomFactor += DeltaTime / 0.5f;
}
else {
ZoomFactor -= DeltaTime / 0.25f;
}
ZoomFactor = FMath::Clamp<float>(ZoomFactor, 0.0f, 1.0f);
CameraComp->FieldOfView = FMath::Lerp<float>(90.0f, 60.0f, ZoomFactor);
SpringArmComp->TargetArmLength = FMath::Lerp<float>(400.0f, 300.0f, ZoomFactor);
{
FRotator NewRotation = GetActorRotation();
NewRotation.Yaw += CameraInput.X;
SetActorRotation(NewRotation);
}
{
FRotator NewRotation = SpringArmComp->GetComponentRotation();
NewRotation.Pitch = FMath::Clamp(NewRotation.Pitch + CameraInput.Y, -80.0f, -15.0f);
SpringArmComp->SetWorldRotation(NewRotation);
}
{
if (!MovementInput.IsZero())
{
//Scale our movement input axis values by 100 units per second
MovementInput = MovementInput.GetSafeNormal() * 100.0f;
FVector NewLocation = GetActorLocation();
NewLocation += GetActorForwardVector() * MovementInput.X * DeltaTime;
NewLocation += GetActorRightVector() * MovementInput.Y * DeltaTime;
SetActorLocation(NewLocation);
}
}
}
// Called to bind functionality to input
void APawnWithCamera::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
InputComponent->BindAction("ZoomIn", IE_Pressed, this, &APawnWithCamera::ZoomIn);
InputComponent->BindAction("ZoomIn", IE_Released, this, &APawnWithCamera::ZoomOut);
InputComponent->BindAxis("MoveForward", this, &APawnWithCamera::MoveForward);
InputComponent->BindAxis("MoveRight", this, &APawnWithCamera::MoveRight);
InputComponent->BindAxis("CameraPitch", this, &APawnWithCamera::PitchCamera);
InputComponent->BindAxis("CameraYaw", this, &APawnWithCamera::YawCamera);
}
void APawnWithCamera::MoveForward(float AxisValue) {
MovementInput.X = FMath::Clamp<float>(AxisValue, -1.0f, 1.0f);
}
void APawnWithCamera::MoveRight(float AxisValue) {
MovementInput.Y = FMath::Clamp<float>(AxisValue, -1.0f, 1.0f);
}
void APawnWithCamera::PitchCamera(float AxisValue) {
CameraInput.Y = AxisValue;
}
void APawnWithCamera::YawCamera(float AxisValue) {
CameraInput.X = AxisValue;
}
void APawnWithCamera::ZoomIn() {
bZoomingIn = true;
}
void APawnWithCamera::ZoomOut() {
bZoomingIn = false;
}
边栏推荐
- Providers and consumers tags in zfoo
- Cmake learning
- Cesium keyboard and mouse control camera roaming (source code + principle explanation)
- Construction and application progress of ten billion level knowledge map of meituan brain
- 集群聊天服务器为什么引入负载均衡器
- Protocol buffers 的问题和滥用
- MySql的DDL和DML和DQL的基本语法
- Boost Filesystem使用手册
- Several methods of obtaining longitude and latitude by cesium
- [attack and defense world web] difficulty four-star 12 point advanced question: confusion1
猜你喜欢

Protocol buffers 的问题和滥用

221. Largest square ● &1277. Square submatrix with statistics all 1 ● ●

flink原理及开发总结(详细)

Chapter1 data cleaning

High numbers | calculation of double integral 2 | high numbers | handwritten notes

Synchro esp32c3 Hardware Configuration Information serial port Print Output

Day109.尚医通:集成Nacos、医院列表、下拉列表查询、医院上线功能、医院详情查询

Looking for the missing class name

Practice data Lake iceberg lesson 37 kakfa write the enfour, not enfour test of iceberg's icberg table

集群聊天服务器为什么引入负载均衡器
随机推荐
Protocol buffers 的问题和滥用
Serveur de chat de Cluster: conception de la table de base de données
Cluster chat server: chatservice business layer
Kuberntes cloud native combat VI uses rook to build CEPH cluster
数据库系统概论第五版课后习题——第一章 绪论
Flink principle and development summary (detailed)
Day109.尚医通:集成Nacos、医院列表、下拉列表查询、医院上线功能、医院详情查询
[Yugong series] June 2022.Net architecture class 084- micro service topic ABP vNext micro service communication
Synchronized同步锁的基本原理
prime_ series_ level-1
Basic principle of synchronized lock
-2021 sorting and sharing of the latest required papers related to comparative learning
googletest
Minimum spanning tree: prim
221. Largest square ● &1277. Square submatrix with statistics all 1 ● ●
C——文件
scala编程(中级进阶实验应用)
Openlayers instances advanced mapbox vector tiles advanced mapbox vector maps
实验设计
合宙ESP32C3硬件配置信息串口打印輸出