当前位置:网站首页>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;
}
边栏推荐
- Cookie 和 Session
- Basic syntax of MySQL DDL and DML and DQL
- First acquaintance with JS (programming suitable for beginners)
- -2021 sorting and sharing of the latest required papers related to comparative learning
- 寻找消失的类名
- Union and union all of Hana SQL
- 合宙ESP32C3硬件配置信息串口打印輸出
- High numbers | calculation of double integral 3 | high numbers | handwritten notes
- 如何在 pyqt 中实现桌面歌词
- Synchro esp32c3 Hardware Configuration Information serial port Print Output
猜你喜欢

Unity—3D数学-Vector3

【愚公系列】2022年06月 .NET架构班 084-微服务专题 Abp vNext微服务通信
![[Yugong series] June 2022.Net architecture class 084- micro service topic ABP vNext micro service communication](/img/29/b73edbdb2409f40c904d126f9185d1.png)
[Yugong series] June 2022.Net architecture class 084- micro service topic ABP vNext micro service communication

NLP field history most complete must read classic papers classification, sorting and sharing (with Chinese analysis)

集群聊天服務器:數據庫錶的設計
![[create birthday card application]](/img/56/e04a9a20e181ad7b68b0f2d1d118bc.png)
[create birthday card application]

At 12 o'clock on July 23, 2022, the deviation from the top of the line of love life hour appeared, maintaining a downward trend and waiting for the rebound signal.

MySql的DDL和DML和DQL的基本语法

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

LeetCode_ 376_ Wobble sequence
随机推荐
One of QT desktop whiteboard tools (to solve the problem of unsmooth curve -- Bezier curve)
数据库系统概论第五版课后习题——第一章 绪论
[arXiv] notes on uploading papers for the first time
Openlayers instance advanced view positioning advanced view positioning
Openlayers instance accessible map accessible map
Given an array composed of numbers, realize the name whose output ID is a number and sorted from small to large
TreeMap
二分函数细节
节流和防抖的说明和实现
What is Kai Niu? Excuse me, is it safe to open a stock account by mobile phone?
Leaderboard design in game server
It's good to change jobs for a while, and it's good to change jobs all the time?
googletest
Summary of database stress testing methods
Protocol buffers 的问题和滥用
Cluster chat server: how to solve the problem of cross server communication | redis publish subscribe
基于速度、复杂性等因素比较KernelSHAP和TreeSHAP
阿里onedate分层思想
Cesium keyboard and mouse control camera roaming (source code + principle explanation)
LeetCode_376_摆动序列