fix
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include "InputActionValue.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "NERGUS.h"
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
|
||||
ANERGUSCharacter::ANERGUSCharacter()
|
||||
{
|
||||
@@ -18,20 +20,41 @@ ANERGUSCharacter::ANERGUSCharacter()
|
||||
// Create the first person mesh that will be viewed only by this character's owner
|
||||
FirstPersonMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("First Person Mesh"));
|
||||
|
||||
FirstPersonMesh->SetupAttachment(GetMesh());
|
||||
|
||||
|
||||
// Create the SpringArm Component
|
||||
FirstPersonSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("First Person Spring Arm"));
|
||||
FirstPersonSpringArm->SetupAttachment(RootComponent);
|
||||
|
||||
// Create the ArmSwaySphere
|
||||
SwayComponent = CreateDefaultSubobject<USphereComponent>(TEXT("ArmSwaySphere"));
|
||||
SwayComponent->SetupAttachment(FirstPersonSpringArm);
|
||||
|
||||
// FirstPersonMesh->SetupAttachment(GetMesh());
|
||||
FirstPersonMesh->SetupAttachment(SwayComponent);
|
||||
FirstPersonMesh->SetOnlyOwnerSee(true);
|
||||
FirstPersonMesh->FirstPersonPrimitiveType = EFirstPersonPrimitiveType::FirstPerson;
|
||||
FirstPersonMesh->SetCollisionProfileName(FName("NoCollision"));
|
||||
|
||||
|
||||
// Create the Arm Mesh
|
||||
FirstPersonArmMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("First person arm"));
|
||||
FirstPersonArmMesh->SetupAttachment(SwayComponent);
|
||||
|
||||
// Create the Camera Component
|
||||
FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("First Person Camera"));
|
||||
FirstPersonCameraComponent->SetupAttachment(FirstPersonMesh, FName("head"));
|
||||
//FirstPersonCameraComponent->SetupAttachment(FirstPersonMesh, FName("head"));
|
||||
FirstPersonCameraComponent->SetupAttachment(FirstPersonArmMesh);
|
||||
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;
|
||||
|
||||
|
||||
|
||||
// FirstPersoSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("First Person SpringArm"));
|
||||
// FirstPersoSpringArm->SetupAttachment(RootComponent);
|
||||
|
||||
// configure the character comps
|
||||
GetMesh()->SetOwnerNoSee(true);
|
||||
@@ -40,8 +63,18 @@ ANERGUSCharacter::ANERGUSCharacter()
|
||||
GetCapsuleComponent()->SetCapsuleSize(34.0f, 96.0f);
|
||||
|
||||
// Configure character movement
|
||||
GetCharacterMovement()->BrakingDecelerationFalling = 1500.0f;
|
||||
GetCharacterMovement()->AirControl = 0.5f;
|
||||
//GetCharacterMovement()->BrakingDecelerationFalling = 1500.0f;
|
||||
//GetCharacterMovement()->AirControl = 0.5f;
|
||||
}
|
||||
|
||||
void ANERGUSCharacter::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
if (IsLocallyControlled())
|
||||
{
|
||||
SwayFunction(DeltaTime);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ANERGUSCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
@@ -50,7 +83,7 @@ void ANERGUSCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
|
||||
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(PlayerInputComponent))
|
||||
{
|
||||
// Jumping
|
||||
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &ANERGUSCharacter::DoJumpStart);
|
||||
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ANERGUSCharacter::DoJumpStart);
|
||||
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ANERGUSCharacter::DoJumpEnd);
|
||||
|
||||
// Moving
|
||||
@@ -67,6 +100,8 @@ void ANERGUSCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ANERGUSCharacter::MoveInput(const FInputActionValue& Value)
|
||||
{
|
||||
// get the Vector2D move axis
|
||||
@@ -80,10 +115,16 @@ void ANERGUSCharacter::MoveInput(const FInputActionValue& Value)
|
||||
void ANERGUSCharacter::LookInput(const FInputActionValue& Value)
|
||||
{
|
||||
// get the Vector2D look axis
|
||||
FVector2D LookAxisVector = Value.Get<FVector2D>();
|
||||
const FVector2D LookAxisValue = Value.Get<FVector2D>();
|
||||
|
||||
// pass the axis values to the aim input
|
||||
DoAim(LookAxisVector.X, LookAxisVector.Y);
|
||||
// DoAim(LookAxisVector.X, LookAxisVector.Y);
|
||||
|
||||
AddControllerYawInput(LookAxisValue.X);
|
||||
AddControllerPitchInput(LookAxisValue.Y);
|
||||
|
||||
CurrentLookInput = LookAxisValue;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -118,3 +159,28 @@ void ANERGUSCharacter::DoJumpEnd()
|
||||
// pass StopJumping to the character
|
||||
StopJumping();
|
||||
}
|
||||
|
||||
void ANERGUSCharacter::SwayFunction(float DeltaTime)
|
||||
{
|
||||
FRotator SwayRotation = SwayComponent->GetRelativeRotation();
|
||||
FRotator LookTarget = FRotator(-CurrentLookInput.Y * 2.0f , CurrentLookInput.X * 2.0f , CurrentLookInput.X * 1.5f);
|
||||
|
||||
FVector CorrentVec = FVector(SwayRotation.Pitch,SwayRotation.Yaw,SwayRotation.Roll);
|
||||
FVector TargetVec = FVector(LookTarget.Pitch,LookTarget.Yaw,LookTarget.Roll);
|
||||
|
||||
FVector SmoothedVec = UKismetMathLibrary::VectorSpringInterp(CorrentVec, TargetVec, SwaySpringState, 40.0f, 0.7f, DeltaTime, 1.0f);
|
||||
|
||||
GEngine->AddOnScreenDebugMessage(1,1,FColor::White,FString::Printf(TEXT("SmoothedVec X = %f"), SmoothedVec.X));
|
||||
|
||||
SmoothedVec.X = FMath::Clamp(SmoothedVec.X, -10.0f, 10.0f);
|
||||
SmoothedVec.Y = FMath::Clamp(SmoothedVec.Y, -10.0f, 10.0f);
|
||||
SmoothedVec.Z = FMath::Clamp(SmoothedVec.Z, -10.0f, 10.0f);
|
||||
|
||||
GEngine->AddOnScreenDebugMessage(1,1,FColor::White,FString::Printf(TEXT("SmoothedVec X = %f"), SmoothedVec.X));
|
||||
GEngine->AddOnScreenDebugMessage(2,1,FColor::White,FString::Printf(TEXT("SmoothedVec Y = %f"), SmoothedVec.Y));
|
||||
GEngine->AddOnScreenDebugMessage(3,1,FColor::White,FString::Printf(TEXT("SmoothedVec Z = %f"), SmoothedVec.Z));
|
||||
|
||||
SwayComponent->SetRelativeRotation(FRotator(SmoothedVec.X , SmoothedVec.Y , SmoothedVec.Z));
|
||||
|
||||
CurrentLookInput = FVector2D::ZeroVector;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
#include "Logging/LogMacros.h"
|
||||
#include "NERGUSCharacter.generated.h"
|
||||
|
||||
class UInputComponent;
|
||||
class USkeletalMeshComponent;
|
||||
class USpringArmComponent;
|
||||
class UCameraComponent;
|
||||
class UInputAction;
|
||||
class USceneComponent;
|
||||
|
||||
struct FInputActionValue;
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogTemplateCharacter, Log, All);
|
||||
@@ -30,6 +35,17 @@ class ANERGUSCharacter : public ACharacter
|
||||
/** First person camera */
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components", meta = (AllowPrivateAccess = "true"))
|
||||
UCameraComponent* FirstPersonCameraComponent;
|
||||
|
||||
/** First person SpringArm */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Components", meta = (AllowPrivateAccess = "true"))
|
||||
USpringArmComponent* FirstPersonSpringArm;
|
||||
|
||||
/** Pawn mesh: first person view (arms; seen only by self) */
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components", meta = (AllowPrivateAccess = "true"))
|
||||
USkeletalMeshComponent* FirstPersonArmMesh;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components", meta = (AllowPrivateAccess = "true"))
|
||||
USphereComponent* SwayComponent;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -49,6 +65,16 @@ protected:
|
||||
UPROPERTY(EditAnywhere, Category ="Input")
|
||||
class UInputAction* MouseLookAction;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Sway")
|
||||
FVector2D CurrentLookInput;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Sway")
|
||||
FVector2D CurrentMoveInput;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Sway")
|
||||
FVectorSpringState SwaySpringState;
|
||||
|
||||
|
||||
public:
|
||||
ANERGUSCharacter();
|
||||
|
||||
@@ -75,6 +101,9 @@ protected:
|
||||
/** Handles jump end inputs from either controls or UI interfaces */
|
||||
UFUNCTION(BlueprintCallable, Category="Input")
|
||||
virtual void DoJumpEnd();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Sway")
|
||||
void SwayFunction(float DeltaTime);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -89,6 +118,9 @@ public:
|
||||
|
||||
/** Returns first person camera component **/
|
||||
UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; }
|
||||
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user