//按键绑定
PlayerInputComponent->BindAction("Sprint", IE_Pressed, this, &ALeamCppCharacter::SprintBegin);
PlayerInputComponent->BindAction("Sprint", IE_Released, this, &ALeamCppCharacter::SprintStop);
//头文件
#include "GameFramework/CharacterMovementComponent.h"
//对应函数,h里声明完的实现
void ALeamCppCharacter::SprintBegin()
{
GetCharacterMovement()->MaxWalkSpeed = 2200;
}
void ALeamCppCharacter::SprintStop()
{
GetCharacterMovement()->MaxWalkSpeed = 600;
}
//二倍镜
ALeamCppCharacter::ALeamCppCharacter()
{
PrimaryActorTick.bCanEverTick = true;//Tick是否被启用
}
void ALeamCppCharacter::BeginPlay()
{//时间轴
FloatCurve = NewObject<UCurveFloat>();
FloatCurve->FloatCurve.AddKey(0, 90);
FloatCurve->FloatCurve.AddKey(0.3, 45);
FOnTimelineFloatStatic OnTimeCallback;
OnTimeCallback.BindUFunction(this, TEXT("DoZoom"));
ZoomTimeline.AddInterpFloat(FloatCurve, OnTimeCallback);
}
void ALeamCppCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
PlayerInputComponent->BindAction("Zoom", IE_Pressed, this, &ALeamCppCharacter::ZoomBegin);
PlayerInputComponent->BindAction("Zoom", IE_Released, this, &ALeamCppCharacter::ZoomStop);
}
void ALeamCppCharacter::ZoomBegin()
{
//FirstPersonCameraComponent->FieldOfView = 45;
ZoomTimeline.Play();
}
void ALeamCppCharacter::ZoomStop()
{
//FirstPersonCameraComponent->FieldOfView = 90;
ZoomTimeline.Reverse();
}
void ALeamCppCharacter::DoZoom(float FieldOfView)
{
FirstPersonCameraComponent->SetFieldOfView(FieldOfView);
}
void ALeamCppCharacter::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
ZoomTimeline.TickTimeline(DeltaSeconds);
}