(Feat) Add Animation

This commit is contained in:
2026-08-06 13:27:21 +02:00
parent fca1b271f1
commit 72a34f6e40
64 changed files with 1943 additions and 83 deletions
@@ -0,0 +1,62 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "FpsArmsAnimInstance.h"
#include "FpsPlayer.h"
#include "GameFramework/CharacterMovementComponent.h"
void UFpsArmsAnimInstance::NativeInitializeAnimation()
{
Super::NativeInitializeAnimation();
OwningPlayer = Cast<AFpsPlayer>(TryGetPawnOwner());
}
void UFpsArmsAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
Super::NativeUpdateAnimation(DeltaSeconds);
// L'AnimInstance est initialisee avec le composant, c'est-a-dire potentiellement
// avant que le pawn soit completement en place. On retente donc tant qu'on n'a
// personne, plutot que d'abandonner definitivement sur un echec au demarrage.
if (!OwningPlayer.IsValid())
{
OwningPlayer = Cast<AFpsPlayer>(TryGetPawnOwner());
if (!OwningPlayer.IsValid())
{
return;
}
}
const AFpsPlayer* Player = OwningPlayer.Get();
const UCharacterMovementComponent* Movement = Player->GetCharacterMovement();
if (!Movement)
{
return;
}
// Size2D et pas Size : en pleine chute la composante verticale ferait courir
// les bras alors que le joueur ne pose pas un pied.
GroundSpeed = Movement->Velocity.Size2D();
// Le test d'acceleration est ce qui distingue « le joueur avance » de « le
// joueur a lache la touche et glisse encore ». Sans lui, l'animation de course
// continue pendant toute la decceleration, les pieds patinant dans le vide --
// invisible sur des bras, mais le meme AnimInstance servira au corps un jour.
bIsMoving = GroundSpeed > MovingSpeedThreshold
&& !Movement->GetCurrentAcceleration().IsNearlyZero();
bIsSprinting = Player->IsSprinting();
bIsFalling = Movement->IsFalling();
bIsCrouching = Movement->IsCrouching();
// La cadence suit la vitesse REELLE et pas l'etat de sprint : c'est ce qui
// fait que les bras accelerent pendant la montee en vitesse, au lieu de
// sauter d'une cadence a l'autre a l'instant ou la touche est pressee.
// Elle couvre donc aussi l'accroupi, gratuitement.
LocomotionPlayRate = FMath::Clamp(
GroundSpeed / ReferenceLocomotionSpeed,
MinLocomotionPlayRate,
MaxLocomotionPlayRate);
}