Added Crunch and Finished Animation with Foot IK
This commit is contained in:
50
Source/Crunch/Private/Animations/CAnimInstance.cpp
Normal file
50
Source/Crunch/Private/Animations/CAnimInstance.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Multiplayer By Caleb
|
||||
|
||||
|
||||
#include "Animations/CAnimInstance.h"
|
||||
|
||||
#include "GameFramework/Character.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
|
||||
void UCAnimInstance::NativeInitializeAnimation()
|
||||
{
|
||||
Super::NativeInitializeAnimation();
|
||||
|
||||
OwnerCharacter = Cast<ACharacter>(TryGetPawnOwner());
|
||||
if (OwnerCharacter)
|
||||
{
|
||||
OwnerMovementComp = OwnerCharacter->GetCharacterMovement();
|
||||
}
|
||||
}
|
||||
|
||||
void UCAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
|
||||
{
|
||||
Super::NativeUpdateAnimation(DeltaSeconds);
|
||||
if (OwnerCharacter)
|
||||
{
|
||||
Speed = OwnerCharacter->GetVelocity().Length();
|
||||
const auto BodyRot{OwnerCharacter->GetActorRotation()};
|
||||
const auto BodyRotDelta{UKismetMathLibrary::NormalizedDeltaRotator(BodyRot, BodyPrevRot)};
|
||||
BodyPrevRot = BodyRot;
|
||||
|
||||
YawSpeed = BodyRotDelta.Yaw / DeltaSeconds;
|
||||
SmoothedYawSpeed = UKismetMathLibrary::FInterpTo(
|
||||
SmoothedYawSpeed,
|
||||
YawSpeed,
|
||||
DeltaSeconds,
|
||||
YawSpeedSmoothLerpSpeed
|
||||
);
|
||||
const auto ControlRot{OwnerCharacter->GetBaseAimRotation()};
|
||||
LookRotOffset = UKismetMathLibrary::NormalizedDeltaRotator(ControlRot, BodyRot);
|
||||
}
|
||||
if (OwnerMovementComp)
|
||||
{
|
||||
bIsJumping = OwnerMovementComp->IsFalling();
|
||||
}
|
||||
}
|
||||
|
||||
void UCAnimInstance::NativeThreadSafeUpdateAnimation(float DeltaSeconds)
|
||||
{
|
||||
Super::NativeThreadSafeUpdateAnimation(DeltaSeconds);
|
||||
}
|
||||
29
Source/Crunch/Private/Character/CCharacter.cpp
Normal file
29
Source/Crunch/Private/Character/CCharacter.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
// Multiplayer By Caleb
|
||||
|
||||
|
||||
#include "Crunch/Public/Character/CCharacter.h"
|
||||
|
||||
|
||||
// Sets default values
|
||||
ACCharacter::ACCharacter()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
GetMesh()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||
}
|
||||
|
||||
void ACCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
void ACCharacter::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
}
|
||||
|
||||
void ACCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
}
|
||||
|
||||
97
Source/Crunch/Private/Character/CPlayerCharacter.cpp
Normal file
97
Source/Crunch/Private/Character/CPlayerCharacter.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
// Multiplayer By Caleb
|
||||
|
||||
|
||||
#include "Crunch/Public/Character/CPlayerCharacter.h"
|
||||
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "Crunch/Public/Player/CPlayerController.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
|
||||
|
||||
ACPlayerCharacter::ACPlayerCharacter()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
CameraBoom = CreateDefaultSubobject<USpringArmComponent>("CameraBoom");
|
||||
CameraBoom->SetupAttachment(GetRootComponent());
|
||||
CameraBoom->bUsePawnControlRotation = true;
|
||||
|
||||
ViewCamera = CreateDefaultSubobject<UCameraComponent>("ViewCamera");
|
||||
ViewCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
|
||||
|
||||
bUseControllerRotationYaw = false;
|
||||
GetCharacterMovement()->bOrientRotationToMovement = true;
|
||||
GetCharacterMovement()->RotationRate = RotationRate;
|
||||
}
|
||||
|
||||
void ACPlayerCharacter::PawnClientRestart()
|
||||
{
|
||||
Super::PawnClientRestart();
|
||||
|
||||
if (const auto OwningPlayerController{GetController<ACPlayerController>()})
|
||||
{
|
||||
const auto InputSubsystem{
|
||||
OwningPlayerController->GetLocalPlayer()->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>()
|
||||
};
|
||||
if (InputSubsystem)
|
||||
{
|
||||
InputSubsystem->RemoveMappingContext(GameplayMappingContext);
|
||||
InputSubsystem->AddMappingContext(GameplayMappingContext, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ACPlayerCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void ACPlayerCharacter::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
}
|
||||
|
||||
void ACPlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
if (const auto EnhancedInputComp{Cast<UEnhancedInputComponent>(PlayerInputComponent)})
|
||||
{
|
||||
EnhancedInputComp->BindAction(JumpInputAction, ETriggerEvent::Triggered, this, &ThisClass::Jump);
|
||||
EnhancedInputComp->BindAction(LookInputAction, ETriggerEvent::Triggered, this, &ThisClass::HandleLookInput);
|
||||
EnhancedInputComp->BindAction(MoveInputAction, ETriggerEvent::Triggered, this, &ThisClass::HandleMoveInput);
|
||||
}
|
||||
}
|
||||
|
||||
void ACPlayerCharacter::HandleLookInput(const FInputActionValue& InputActionValue)
|
||||
{
|
||||
const FVector2D InputVal{InputActionValue.Get<FVector2D>()};
|
||||
|
||||
AddControllerPitchInput(-InputVal.Y);
|
||||
AddControllerYawInput(InputVal.X);
|
||||
}
|
||||
|
||||
void ACPlayerCharacter::HandleMoveInput(const FInputActionValue& InputActionValue)
|
||||
{
|
||||
FVector2D InputVal{InputActionValue.Get<FVector2D>()};
|
||||
InputVal.Normalize();
|
||||
|
||||
AddMovementInput(GetMoveFwdDir() * InputVal.Y + GetLookRightDir() * InputVal.X);
|
||||
}
|
||||
|
||||
FVector ACPlayerCharacter::GetLookRightDir() const
|
||||
{
|
||||
return ViewCamera->GetRightVector();
|
||||
}
|
||||
|
||||
FVector ACPlayerCharacter::GetLookFwdDir() const
|
||||
{
|
||||
return ViewCamera->GetForwardVector();
|
||||
}
|
||||
|
||||
FVector ACPlayerCharacter::GetMoveFwdDir() const
|
||||
{
|
||||
return FVector::CrossProduct(GetLookRightDir(), FVector::UpVector);
|
||||
}
|
||||
4
Source/Crunch/Private/Game/CGameMode.cpp
Normal file
4
Source/Crunch/Private/Game/CGameMode.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
// Multipalyer By Caleb
|
||||
|
||||
|
||||
#include "Crunch/Public/Game/CGameMode.h"
|
||||
5
Source/Crunch/Private/Player/CPlayerController.cpp
Normal file
5
Source/Crunch/Private/Player/CPlayerController.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// Multipalyer By Caleb
|
||||
|
||||
|
||||
#include "Crunch/Public/Player/CPlayerController.h"
|
||||
|
||||
64
Source/Crunch/Public/Animations/CAnimInstance.h
Normal file
64
Source/Crunch/Public/Animations/CAnimInstance.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// Multiplayer By Caleb
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Animation/AnimInstance.h"
|
||||
#include "CAnimInstance.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CRUNCH_API UCAnimInstance : public UAnimInstance
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual void NativeInitializeAnimation() override;
|
||||
virtual void NativeUpdateAnimation(float DeltaSeconds) override;
|
||||
virtual void NativeThreadSafeUpdateAnimation(float DeltaSeconds) override;
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta=(BlueprintThreadSafe))
|
||||
FORCEINLINE float GetSpeed() const { return Speed; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta=(BlueprintThreadSafe))
|
||||
FORCEINLINE bool IsMoving() const { return Speed != 0; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta=(BlueprintThreadSafe))
|
||||
FORCEINLINE bool IsNotMoving() const { return Speed == 0; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta=(BlueprintThreadSafe))
|
||||
FORCEINLINE float GetYawSpeed() const { return YawSpeed; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta=(BlueprintThreadSafe))
|
||||
FORCEINLINE float GetSmoothedYaw() const { return SmoothedYawSpeed; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta=(BlueprintThreadSafe))
|
||||
FORCEINLINE bool GetIsJumping() const { return bIsJumping; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta=(BlueprintThreadSafe))
|
||||
FORCEINLINE bool IsOnGround() const { return !bIsJumping; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta=(BlueprintThreadSafe))
|
||||
FORCEINLINE float GetLookYawOffset() const { return LookRotOffset.Yaw; }
|
||||
UFUNCTION(BlueprintCallable, meta=(BlueprintThreadSafe))
|
||||
FORCEINLINE float GetLookPitchOffset() const { return LookRotOffset.Pitch; }
|
||||
|
||||
private:
|
||||
UPROPERTY()
|
||||
class ACharacter* OwnerCharacter;
|
||||
UPROPERTY()
|
||||
class UCharacterMovementComponent* OwnerMovementComp;
|
||||
UPROPERTY()
|
||||
float Speed{0.f};
|
||||
float YawSpeed{0.f};
|
||||
float SmoothedYawSpeed{0.f};
|
||||
bool bIsJumping{false};
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Animation")
|
||||
float YawSpeedSmoothLerpSpeed{1.f};
|
||||
|
||||
FRotator BodyPrevRot{};
|
||||
FRotator LookRotOffset{};
|
||||
};
|
||||
24
Source/Crunch/Public/Character/CCharacter.h
Normal file
24
Source/Crunch/Public/Character/CCharacter.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// Multiplayer By Caleb
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "CCharacter.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class CRUNCH_API ACCharacter : public ACharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ACCharacter();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
};
|
||||
52
Source/Crunch/Public/Character/CPlayerCharacter.h
Normal file
52
Source/Crunch/Public/Character/CPlayerCharacter.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// Multiplayer By Caleb
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CCharacter.h"
|
||||
#include "CPlayerCharacter.generated.h"
|
||||
|
||||
struct FInputActionValue;
|
||||
|
||||
UCLASS()
|
||||
class CRUNCH_API ACPlayerCharacter : public ACCharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ACPlayerCharacter();
|
||||
virtual void PawnClientRestart() override;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
private:
|
||||
UPROPERTY(VisibleDefaultsOnly, Category= "View")
|
||||
class USpringArmComponent* CameraBoom;
|
||||
UPROPERTY(VisibleDefaultsOnly, Category= "View")
|
||||
class UCameraComponent* ViewCamera;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category= "View")
|
||||
FRotator RotationRate{FRotator(0.0f, 720.0f, 0.0f)};
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category= "Input")
|
||||
class UInputMappingContext* GameplayMappingContext;
|
||||
UPROPERTY(EditDefaultsOnly, Category= "Input")
|
||||
class UInputAction* JumpInputAction;
|
||||
UPROPERTY(EditDefaultsOnly, Category= "Input")
|
||||
UInputAction* LookInputAction;
|
||||
UPROPERTY(EditDefaultsOnly, Category= "Input")
|
||||
UInputAction* MoveInputAction;
|
||||
|
||||
void HandleLookInput(const FInputActionValue& InputActionValue);
|
||||
void HandleMoveInput(const FInputActionValue& InputActionValue);
|
||||
|
||||
FVector GetLookRightDir() const;
|
||||
FVector GetLookFwdDir() const;
|
||||
FVector GetMoveFwdDir() const;
|
||||
|
||||
};
|
||||
16
Source/Crunch/Public/Game/CGameMode.h
Normal file
16
Source/Crunch/Public/Game/CGameMode.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// Multipalyer By Caleb
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "CGameMode.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CRUNCH_API ACGameMode : public AGameModeBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
||||
16
Source/Crunch/Public/Player/CPlayerController.h
Normal file
16
Source/Crunch/Public/Player/CPlayerController.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// Multipalyer By Caleb
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "CPlayerController.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CRUNCH_API ACPlayerController : public APlayerController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
||||
Reference in New Issue
Block a user