Update animation

This commit is contained in:
2024-09-09 04:25:47 -04:00
parent 92090a3ae5
commit 0ea090dba1
5 changed files with 190 additions and 34 deletions
@@ -6,12 +6,13 @@
#include "Engine/LocalPlayer.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "GameFramework/Controller.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "InputActionValue.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "WorldPartition/ContentBundle/ContentBundleLog.h"
DEFINE_LOG_CATEGORY(LogLumiCharacter);
@@ -24,6 +25,9 @@ ALumiCharacter::ALumiCharacter()
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(35.0f, 90.0f);
// Allow double jumping
JumpMaxCount = 2;
// Don't rotate when the controller rotates. Let that just affect the camera.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
@@ -42,6 +46,11 @@ ALumiCharacter::ALumiCharacter()
FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
}
ELumiStance ALumiCharacter::GetCurrentStance() const
{
return CurrentStance;
}
// Called when the game starts or when spawned
void ALumiCharacter::BeginPlay()
{
@@ -76,26 +85,30 @@ void ALumiCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompo
EnhancedInputComponent->BindAction(GrabAction,
ETriggerEvent::Triggered,
this,
&ALumiCharacter::OnGrabTriggered);
&ALumiCharacter::OnGrabActionTriggered);
// Jumping
EnhancedInputComponent->BindAction(JumpAction,
ETriggerEvent::Started,
this,
&ACharacter::Jump);
&ALumiCharacter::OnJumpActionStarted);
EnhancedInputComponent->BindAction(JumpAction,
ETriggerEvent::Ongoing,
this,
&ALumiCharacter::OnJumpActionOngoing);
EnhancedInputComponent->BindAction(JumpAction,
ETriggerEvent::Completed,
this,
&ACharacter::StopJumping);
&ALumiCharacter::OnJumpActionCompleted);
// Moving
EnhancedInputComponent->BindAction(MoveAction,
ETriggerEvent::Triggered,
this,
&ALumiCharacter::OnMoveTriggered);
&ALumiCharacter::OnMoveActionTriggered);
// Looking
EnhancedInputComponent->BindAction(LookAction,
ETriggerEvent::Triggered,
this,
&ALumiCharacter::OnLookTriggered);
&ALumiCharacter::OnLookActionTriggered);
}
else
{
@@ -112,29 +125,29 @@ void ALumiCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompo
}
}
void ALumiCharacter::OnGrabTriggered(const FInputActionValue& Value)
void ALumiCharacter::OnGrabActionTriggered(const FInputActionValue& Value)
{
UE_LOG(LogLumiCharacter, Log, TEXT("Grab Triggered"));
}
void ALumiCharacter::OnJumpStarted(const FInputActionValue& Value)
void ALumiCharacter::OnJumpActionStarted(const FInputActionValue& Value)
{
// Broadcast that the jump has started
OnJumpStarted.Broadcast();
Jump();
}
void ALumiCharacter::OnJumpHold(const FInputActionValue& Value)
void ALumiCharacter::OnJumpActionOngoing(const FInputActionValue& Value)
{
// Get how long the jump has been held
const float JumpHoldTime = Value.Get<float>();
UE_LOG(LogLumiCharacter, Log, TEXT("Holding Jump for %f seconds"), JumpHoldTime);
}
void ALumiCharacter::OnJumpCompleted(const FInputActionValue& Value)
void ALumiCharacter::OnJumpActionCompleted(const FInputActionValue& Value)
{
StopJumping();
}
void ALumiCharacter::OnMoveTriggered(const FInputActionValue& Value)
void ALumiCharacter::OnMoveActionTriggered(const FInputActionValue& Value)
{
// input is a Vector2D
const FVector2D MovementVector = Value.Get<FVector2D>();
@@ -157,7 +170,7 @@ void ALumiCharacter::OnMoveTriggered(const FInputActionValue& Value)
}
}
void ALumiCharacter::OnLookTriggered(const FInputActionValue& Value)
void ALumiCharacter::OnLookActionTriggered(const FInputActionValue& Value)
{
// input is a Vector2D
const FVector2D LookAxisVector = Value.Get<FVector2D>();
@@ -169,3 +182,38 @@ void ALumiCharacter::OnLookTriggered(const FInputActionValue& Value)
AddControllerPitchInput(LookAxisVector.Y);
}
}
void ALumiCharacter::OnDefaultStance_Implementation()
{
UE_LOG(LogLumiCharacter, Log, TEXT("OnDefaultStance_Implementation()"));
}
void ALumiCharacter::OnMagicStance_Implementation()
{
UE_LOG(LogLumiCharacter, Log, TEXT("OnMagicStance_Implementation()"));
}
ELumiStance ALumiCharacter::SetCurrentStance(const ELumiStance NewStance)
{
const ELumiStance OldStance = CurrentStance;
UCharacterMovementComponent* Movement = GetCharacterMovement();
if (NewStance == ELumiStance::Default)
{
Movement->bOrientRotationToMovement = true;
Movement->bUseControllerDesiredRotation = false;
OnDefaultStance();
}
else if (NewStance == ELumiStance::Magic)
{
Movement->bOrientRotationToMovement = false;
Movement->bUseControllerDesiredRotation = true;
OnMagicStance();
}
CurrentStance = NewStance;
return OldStance;
}
@@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "LumiStance.h"
#include "GameFramework/Character.h"
#include "Logging/LogMacros.h"
#include "LumiCharacter.generated.h"
@@ -15,23 +16,31 @@ struct FInputActionValue;
DECLARE_LOG_CATEGORY_EXTERN(LogLumiCharacter, Log, All);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FJumpDelegate);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FStanceChangedDelegate,
ELumiStance, OldStance,
ELumiStance, NewStance);
static const FString PlayerStanceEnumPath = TEXT("/Game/Player/E_PlayerStance");
UCLASS()
class WIZARDINGCENTRAL_API ALumiCharacter : public ACharacter
{
GENERATED_BODY()
// Private UPROPERTIE'S --------------------------------------------------------------------------------------------
/** Camera boom positioning the camera behind the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
USpringArmComponent* CameraBoom;
/** Follow camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
UCameraComponent* FollowCamera;
/** MappingContext */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputMappingContext* DefaultMappingContext;
/** Grab Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* GrabAction;
@@ -44,31 +53,114 @@ class WIZARDINGCENTRAL_API ALumiCharacter : public ACharacter
/** Look Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* LookAction;
public:
// Sets default values for this character's properties
ALumiCharacter();
/** The current stance of the character */
UPROPERTY(BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
ELumiStance CurrentStance = ELumiStance::Default;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// UFUNCTION's -----------------------------------------------------------------------------------------------------
/**
* Set the stance of the character
*
* @param NewStance The new stance to set
* @return The stance before the new stance was set
*/
UFUNCTION(BlueprintCallable, Category = Stance)
ELumiStance SetCurrentStance(ELumiStance NewStance);
/**
* Event called when the character switches to the default stance
*/
UFUNCTION(BlueprintNativeEvent, Category = "Stance")
void OnDefaultStance();
/**
* Event called when the character switches to the magic stance
*/
UFUNCTION(BlueprintNativeEvent, Category = "Stance")
void OnMagicStance();
public:
// Public Virtual Functions ----------------------------------------------------------------------------------------
public:
// Called every frame
// virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
/**
* Called to bind functionality to input
* @param PlayerInputComponent The input component to bind to
*/
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
protected:
// Protected Virtual Functions -------------------------------------------------------------------------------------
/**
* Called when the game starts or when spawned
*/
virtual void BeginPlay() override;
public:
// Public Functions ------------------------------------------------------------------------------------------------
/**
* Sets default values for this character's properties
*/
ALumiCharacter();
/**
* Getter for @property CurrentStance
*
* @return The current stance of the character
*/
ELumiStance GetCurrentStance() const;
private:
// Private Functions -----------------------------------------------------------------------------------------------
// Grab
void OnGrabTriggered(const FInputActionValue& Value);
/**
* Callback for when the grab action is triggered
* @param Value The value of the input action
*/
void OnGrabActionTriggered(const FInputActionValue& Value);
// Jump
void OnJumpStarted(const FInputActionValue& Value);
void OnJumpHold(const FInputActionValue& Value);
void OnJumpCompleted(const FInputActionValue& Value);
/**
* Callback for when the jump action is started
* @param Value The value of the input action
*/
void OnJumpActionStarted(const FInputActionValue& Value);
/**
* Callback for when the jump action is ongoing
* @param Value The value of the input action
*/
void OnJumpActionOngoing(const FInputActionValue& Value);
/**
* Callback for when the jump action is completed
* @param Value The value of the input action
*/
void OnJumpActionCompleted(const FInputActionValue& Value);
// Move
void OnMoveTriggered(const FInputActionValue& Value);
/**
* Callback for when the move action is triggered
* @param Value The value of the input action
*/
void OnMoveActionTriggered(const FInputActionValue& Value);
// Look
void OnLookTriggered(const FInputActionValue& Value);
/**
* Callback for when the look action is triggered
* @param Value The value of the input action
*/
void OnLookActionTriggered(const FInputActionValue& Value);
public:
// Delegates -------------------------------------------------------------------------------------------------------
UPROPERTY(BlueprintAssignable, Category = "Input")
FJumpDelegate OnJumpStarted;
UPROPERTY(BlueprintAssignable, Category = "Stance")
FStanceChangedDelegate OnStanceChanged;
};
@@ -0,0 +1,13 @@
// Copyright Team Lumi. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "LumiStance.generated.h"
UENUM(BlueprintType) // This makes the enum visible to Blueprints
enum class ELumiStance : uint8
{
Default UMETA(DisplayName = "Default Stance"),
Magic UMETA(DisplayName = "Magic Stance"),
};