// Copyright Epic Games, Inc. All Rights Reserved. #include "AudioVideoRecordCharacter.h" #include "Animation/AnimInstance.h" #include "Camera/CameraComponent.h" #include "Components/CapsuleComponent.h" #include "Components/SkeletalMeshComponent.h" #include "EnhancedInputComponent.h" #include "InputActionValue.h" #include "GameFramework/CharacterMovementComponent.h" #include "AudioVideoRecord.h" AAudioVideoRecordCharacter::AAudioVideoRecordCharacter() { // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f); // Create the first person mesh that will be viewed only by this character's owner FirstPersonMesh = CreateDefaultSubobject(TEXT("First Person Mesh")); FirstPersonMesh->SetupAttachment(GetMesh()); FirstPersonMesh->SetOnlyOwnerSee(true); FirstPersonMesh->FirstPersonPrimitiveType = EFirstPersonPrimitiveType::FirstPerson; FirstPersonMesh->SetCollisionProfileName(FName("NoCollision")); // Create the Camera Component FirstPersonCameraComponent = CreateDefaultSubobject(TEXT("First Person Camera")); FirstPersonCameraComponent->SetupAttachment(FirstPersonMesh, FName("head")); FirstPersonCameraComponent->SetRelativeLocationAndRotation(FVector(-2.8f, 5.89f, 0.0f), FRotator(0.0f, 90.0f, -90.0f)); FirstPersonCameraComponent->bUsePawnControlRotation = true; FirstPersonCameraComponent->bEnableFirstPersonFieldOfView = true; FirstPersonCameraComponent->bEnableFirstPersonScale = true; FirstPersonCameraComponent->FirstPersonFieldOfView = 70.0f; FirstPersonCameraComponent->FirstPersonScale = 0.6f; // configure the character comps GetMesh()->SetOwnerNoSee(true); GetMesh()->FirstPersonPrimitiveType = EFirstPersonPrimitiveType::WorldSpaceRepresentation; GetCapsuleComponent()->SetCapsuleSize(34.0f, 96.0f); // Configure character movement GetCharacterMovement()->BrakingDecelerationFalling = 1500.0f; GetCharacterMovement()->AirControl = 0.5f; } void AAudioVideoRecordCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { // Set up action bindings if (UEnhancedInputComponent* EnhancedInputComponent = Cast(PlayerInputComponent)) { // Jumping EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &AAudioVideoRecordCharacter::DoJumpStart); EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &AAudioVideoRecordCharacter::DoJumpEnd); // Moving EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAudioVideoRecordCharacter::MoveInput); // Looking/Aiming EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AAudioVideoRecordCharacter::LookInput); EnhancedInputComponent->BindAction(MouseLookAction, ETriggerEvent::Triggered, this, &AAudioVideoRecordCharacter::LookInput); } else { UE_LOG(LogAudioVideoRecord, Error, TEXT("'%s' Failed to find an Enhanced Input Component! This template is built to use the Enhanced Input system. If you intend to use the legacy system, then you will need to update this C++ file."), *GetNameSafe(this)); } } void AAudioVideoRecordCharacter::MoveInput(const FInputActionValue& Value) { // get the Vector2D move axis FVector2D MovementVector = Value.Get(); // pass the axis values to the move input DoMove(MovementVector.X, MovementVector.Y); } void AAudioVideoRecordCharacter::LookInput(const FInputActionValue& Value) { // get the Vector2D look axis FVector2D LookAxisVector = Value.Get(); // pass the axis values to the aim input DoAim(LookAxisVector.X, LookAxisVector.Y); } void AAudioVideoRecordCharacter::DoAim(float Yaw, float Pitch) { if (GetController()) { // pass the rotation inputs AddControllerYawInput(Yaw); AddControllerPitchInput(Pitch); } } void AAudioVideoRecordCharacter::DoMove(float Right, float Forward) { if (GetController()) { // pass the move inputs AddMovementInput(GetActorRightVector(), Right); AddMovementInput(GetActorForwardVector(), Forward); } } void AAudioVideoRecordCharacter::DoJumpStart() { // pass Jump to the character Jump(); } void AAudioVideoRecordCharacter::DoJumpEnd() { // pass StopJumping to the character StopJumping(); }