RewindCharacter_1
RewindCharacter_1
#include "RewindCharacter.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Engine/LocalPlayer.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/Controller.h"
#include "GameFramework/SpringArmComponent.h"
#include "InputActionValue.h"
#include "RewindComponent.h"
#include "RewindGameMode.h"
#include "RewindVisualizationComponent.h"
DEFINE_LOG_CATEGORY(LogTemplateCharacter);
//////////////////////////////////////////////////////////////////////////
// ARewindCharacter
ARewindCharacter::ARewindCharacter()
{
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
// Don't rotate when the controller rotates. Let that just affect the camera.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Note: For faster iteration times these variables, and many more, can be
tweaked in the Character Blueprint
// instead of recompiling to adjust them
GetCharacterMovement()->JumpZVelocity = 700.f;
GetCharacterMovement()->AirControl = 0.35f;
GetCharacterMovement()->MaxWalkSpeed = 500.f;
GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;
GetCharacterMovement()->BrakingDecelerationFalling = 1500.0f;
// Note: The skeletal mesh and anim blueprint references on the Mesh
component (inherited from Character)
// are set in the derived blueprint asset named ThirdPersonCharacter (to
avoid direct content references in C++)
void ARewindCharacter::BeginPlay()
{
// Call the base class
Super::BeginPlay();
ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController-
>GetLocalPlayer()))
{
Subsystem->AddMappingContext(DefaultMappingContext, 0);
}
}
void ARewindCharacter::SetupPlayerInputComponent(UInputComponent*
PlayerInputComponent)
{
// Set up action bindings
if (UEnhancedInputComponent* EnhancedInputComponent =
Cast<UEnhancedInputComponent>(PlayerInputComponent))
{
// Jumping
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started,
this, &ARewindCharacter::Jump);
EnhancedInputComponent->BindAction(JumpAction,
ETriggerEvent::Completed, this, &ARewindCharacter::StopJumping);
// Moving
EnhancedInputComponent->BindAction(MoveAction,
ETriggerEvent::Triggered, this, &ARewindCharacter::Move);
// Looking
EnhancedInputComponent->BindAction(LookAction,
ETriggerEvent::Triggered, this, &ARewindCharacter::Look);
// Rewind
EnhancedInputComponent->BindAction(RewindAction,
ETriggerEvent::Started, this, &ARewindCharacter::Rewind);
EnhancedInputComponent->BindAction(RewindAction,
ETriggerEvent::Completed, this, &ARewindCharacter::StopRewinding);
// Fast Forward
EnhancedInputComponent->BindAction(FastForwardAction,
ETriggerEvent::Started, this, &ARewindCharacter::FastForward);
EnhancedInputComponent->BindAction(FastForwardAction,
ETriggerEvent::Completed, this, &ARewindCharacter::StopFastForwarding);
void ARewindCharacter::Jump()
{
// Ignore input while manipulating time
if (RewindComponent->IsTimeBeingManipulated()) { return; }
Super::Jump();
}
void ARewindCharacter::StopJumping()
{
// Ignore input while manipulating time
if (RewindComponent->IsTimeBeingManipulated()) { return; }
Super::StopJumping();
}
// input is a Vector2D
FVector2D MovementVector = Value.Get<FVector2D>();
if (Controller != nullptr)
{
// find out which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
void ARewindCharacter::UpdateCamera()
{
if (RewindComponent->IsTimeBeingManipulated())
{
// Switch to bird's eye camera view
CameraBoom->bUsePawnControlRotation = false;
CameraBoom->TargetArmLength = RewindTargetCameraArmLength;
}
else
{
// Restore original camera view
CameraBoom->bUsePawnControlRotation = true;
CameraBoom->TargetArmLength = OriginalTargetCameraArmLength;
}
}