Почему сценарии актеров не появляются на спрайтах персонажа?C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Почему сценарии актеров не появляются на спрайтах персонажа?

Сообщение Anonymous »

Я работаю над таким проектом, как Bodycam с C ++, USUAally работает хорошо, потому что я работал только вводами сценария своих персонажей, сетчаты, камеры ... все они в скрипте персонажа, но когда я начинаю использовать другие сценарии, такие как сценарий «базы оружия» для других оружия. Вся система пошла не так ... сетки, не появляющиеся, пули не работают ... < /p>
BodycamProjectCharacter.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Logging/LogMacros.h"
#include "EnhancedInputComponent.h"
#include "BodycamProjectCharacter.generated.h"

class UInputComponent;
class USkeletalMeshComponent;
class UCameraComponent;
class UInputAction;
class UInputMappingContext;
class USpringArmComponent;
class AWeaponBase;
struct FInputActionValue;

DECLARE_LOG_CATEGORY_EXTERN(LogTemplateCharacter, Log, All);

UCLASS(config = Game)
class ABodycamProjectCharacter : public ACharacter
{
GENERATED_BODY()

/** Spring arm component for camera positioning */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
USpringArmComponent* SpringArmComp;

/** Second spring arm component for additional camera control */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
USpringArmComponent* SpringArmComp2;

/** Pawn mesh: 1st person view (arms; seen only by self) */
UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
USkeletalMeshComponent* Mesh1P;

/** First person camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
UCameraComponent* FirstPersonCameraComponent;

/** MappingContext */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputMappingContext* DefaultMappingContext;

/** Jump Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* JumpAction;

/** Move Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* MoveAction;

/** Look Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* LookAction;

/** Weapon Switch Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* SwitchWeaponAction;

/** Fire Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* FireAction;

/** Reload Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* ReloadAction;

public:
ABodycamProjectCharacter();

protected:
virtual void BeginPlay() override;

public:
/** Bool for AnimBP to switch to another animation set */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Weapon)
bool bHasRifle;

/** Weapon System */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Weapon)
AWeaponBase* PrimaryWeapon;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Weapon)
AWeaponBase* SecondaryWeapon;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Weapon)
TSubclassOf PrimaryWeaponClass;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Weapon)
TSubclassOf SecondaryWeaponClass;

UPROPERTY(BlueprintReadOnly, Category = Weapon)
AWeaponBase* CurrentWeapon;

/*UFUNCTION(BlueprintCallable, Category = Weapon)
void Reload();*/

/** Weapon Functions */
UFUNCTION(BlueprintCallable, Category = Weapon)
void SwitchWeapon();

UFUNCTION(BlueprintCallable, Category = Weapon)
void Fire();

/** Setter to set the bool */
UFUNCTION(BlueprintCallable, Category = Weapon)
void SetHasRifle(bool bNewHasRifle);

/** Getter for the bool */
UFUNCTION(BlueprintCallable, Category = Weapon)
bool GetHasRifle();

protected:
/** Called for movement input */
void Move(const FInputActionValue& Value);

/** Called for looking input */
void Look(const FInputActionValue& Value);

// APawn interface
virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override;

public:
/** Returns Mesh1P subobject **/
USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; }

/** Returns FirstPersonCameraComponent subobject **/
UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; }

public:

/** Get the first person mesh for weapon animations */
UFUNCTION(BlueprintCallable, Category = "Animation")
USkeletalMeshComponent* GetFirstPersonMesh() const { return Mesh1P; }

// Add these to your BodycamProjectCharacter.cpp

void PlayFirstPersonAnimation(UAnimationAsset* AnimToPlay)
{
if (AnimToPlay && Mesh1P)
{
Mesh1P->PlayAnimation(AnimToPlay, false);
}
}

};`

BodycamProjectCharacter.cpp

#include "BodycamProjectCharacter.h"
#include "BodycamProjectProjectile.h"
#include "Animation/AnimInstance.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/SkeletalMeshComponent.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "InputActionValue.h"
#include "Engine/LocalPlayer.h"
#include "GameFramework/SpringArmComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "AWeaponBase.h"

DEFINE_LOG_CATEGORY(LogTemplateCharacter);

//////////////////////////////////////////////////////////////////////////
// ABodycamProjectCharacter

ABodycamProjectCharacter::ABodycamProjectCharacter()
{
// Character doesnt have a rifle at start
bHasRifle = false;

// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f);

// Create first spring arm component
SpringArmComp = CreateDefaultSubobject(TEXT("SpringArmComp"));
SpringArmComp->SetupAttachment(GetCapsuleComponent());
SpringArmComp->bUsePawnControlRotation = true;
SpringArmComp->bEnableCameraLag = true;
SpringArmComp->TargetArmLength = 0.0f;

// Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn)
Mesh1P = CreateDefaultSubobject(TEXT("CharacterMesh1P"));
Mesh1P->SetOnlyOwnerSee(true);
Mesh1P->SetupAttachment(SpringArmComp);
Mesh1P->bCastDynamicShadow = false;
Mesh1P->CastShadow = false;
Mesh1P->SetRelativeLocation(FVector(-30.f, 0.f, -150.f));

// Create second spring arm component
SpringArmComp2 = CreateDefaultSubobject(TEXT("SpringArmComp2"));
SpringArmComp2->SetupAttachment(Mesh1P);
SpringArmComp2->bUsePawnControlRotation = true;
SpringArmComp2->bEnableCameraLag = true;
SpringArmComp2->TargetArmLength = 0.0f;
SpringArmComp2->SetRelativeLocation(FVector(0.f, 0.f, 150.f));

// Create a CameraComponent
FirstPersonCameraComponent = CreateDefaultSubobject(TEXT("FirstPersonCamera"));
FirstPersonCameraComponent->SetupAttachment(SpringArmComp2);
FirstPersonCameraComponent->SetRelativeLocation(FVector(10.f, 0.f, -2.f)); // Position the camera
FirstPersonCameraComponent->bUsePawnControlRotation = true;

// Initialize weapon pointers
PrimaryWeapon = nullptr;
SecondaryWeapon = nullptr;
CurrentWeapon = nullptr;
}

void ABodycamProjectCharacter::BeginPlay()
{
// Call the base class
Super::BeginPlay();

// Movement settings for more realistic feel
GetCharacterMovement()->MaxAcceleration = 600.0f; // Lower = slower acceleration
GetCharacterMovement()->BrakingDecelerationWalking = 1000.0f; // Higher = faster stopping

// Add Input Mapping Context
if (APlayerController* PlayerController = Cast(Controller))
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer()))
{
Subsystem->AddMappingContext(DefaultMappingContext, 0);
}
}

// Spawn and setup primary weapon
if (PrimaryWeaponClass)
{
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = GetInstigator();

PrimaryWeapon = GetWorld()->SpawnActor(PrimaryWeaponClass, SpawnParams);
if (PrimaryWeapon)
{
// Attach weapon to the correct socket on the first person mesh
PrimaryWeapon->AttachToComponent(
Mesh1P,
FAttachmentTransformRules::SnapToTargetIncludingScale,
TEXT("ik_hand_gun") // Make sure this socket exists in your FP mesh
);

// Hide the weapon initially if needed
// PrimaryWeapon->SetActorHiddenInGame(false);
}
}

// Spawn and setup secondary weapon
if (SecondaryWeaponClass)
{
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = GetInstigator();

SecondaryWeapon = GetWorld()->SpawnActor(SecondaryWeaponClass, SpawnParams);
if (SecondaryWeapon)
{
// Attach secondary weapon to a different socket or the same one
SecondaryWeapon->AttachToComponent(
Mesh1P,
FAttachmentTransformRules::SnapToTargetIncludingScale,
TEXT("ik_hand_gun") // Or use a different socket like "SecondaryWeaponSocket"
);

SecondaryWeapon->SetActorHiddenInGame(true); // Hide secondary weapon initially
}
}

// Set primary weapon as current weapon
CurrentWeapon = PrimaryWeapon;
if (CurrentWeapon)
{
CurrentWeapon->DrawWeapon(); // Play draw animation
}

if (PrimaryWeapon)
{
// Load your pistol mesh - replace path with your actual pistol mesh path
USkeletalMesh* PistolMesh = LoadObject(nullptr, TEXT("/BodycamProject/Content/FPS_Pistol_Single/Mesh/Pistol/SK_Pistol"));
if (PistolMesh)
{
PrimaryWeapon->SetWeaponMesh(PistolMesh);
}
}

}

//////////////////////////////////////////////////////////////////////////// Input

void ABodycamProjectCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
// Set up action bindings
if (UEnhancedInputComponent* EnhancedInputComponent = Cast(PlayerInputComponent))
{
// Jumping
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &ACharacter::Jump);
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);

// Moving
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ABodycamProjectCharacter::Move);

// Looking
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ABodycamProjectCharacter::Look);

// Weapon switching
EnhancedInputComponent->BindAction(SwitchWeaponAction, ETriggerEvent::Started, this, &ABodycamProjectCharacter::SwitchWeapon);

// Firing
if (FireAction)
{
EnhancedInputComponent->BindAction(FireAction, ETriggerEvent::Started, this, &ABodycamProjectCharacter::Fire);
}
}
else
{
UE_LOG(LogTemplateCharacter, 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 ABodycamProjectCharacter::Move(const FInputActionValue& Value)
{
// Input is a Vector2D
FVector2D MovementVector = Value.Get();

if (Controller != nullptr)
{
// Add movement
AddMovementInput(GetActorForwardVector(), MovementVector.Y);
AddMovementInput(GetActorRightVector(), MovementVector.X);
}
}

void ABodycamProjectCharacter::Look(const FInputActionValue& Value)
{
// Input is a Vector2D
FVector2D LookAxisVector = Value.Get();

if (Controller != nullptr)
{
// Add yaw and pitch input to controller
AddControllerYawInput(LookAxisVector.X);
AddControllerPitchInput(LookAxisVector.Y);
}
}

void ABodycamProjectCharacter::SwitchWeapon()
{
// Ensure both weapons exist
if (!PrimaryWeapon || !SecondaryWeapon)
{
UE_LOG(LogTemplateCharacter, Warning, TEXT("Cannot switch weapons - one or both weapons are null"));
return;
}

if (CurrentWeapon == PrimaryWeapon)
{
// Switch to secondary weapon
PrimaryWeapon->SetActorHiddenInGame(true);
SecondaryWeapon->SetActorHiddenInGame(false);
CurrentWeapon = SecondaryWeapon;
UE_LOG(LogTemplateCharacter, Log, TEXT("Switched to secondary weapon"));
}
else
{
// Switch to primary weapon
SecondaryWeapon->SetActorHiddenInGame(true);
PrimaryWeapon->SetActorHiddenInGame(false);
CurrentWeapon = PrimaryWeapon;
UE_LOG(LogTemplateCharacter, Log, TEXT("Switched to primary weapon"));
}
}

void ABodycamProjectCharacter::Fire()
{
if (CurrentWeapon)
{
CurrentWeapon->Fire();
UE_LOG(LogTemplateCharacter, Log, TEXT("Firing current weapon"));
}
else
{
UE_LOG(LogTemplateCharacter, Warning, TEXT("No current weapon to fire"));
}
}

void ABodycamProjectCharacter::SetHasRifle(bool bNewHasRifle)
{
bHasRifle = bNewHasRifle;
}

bool ABodycamProjectCharacter::GetHasRifle()
{
return bHasRifle;
}`

AWeaponBase.h

#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "AWeaponBase.generated.h"

UCLASS()
class BODYCAMPROJECT_API AWeaponBase : public AActor
{
GENERATED_BODY()

public:
AWeaponBase();

protected:
/** Weapon's skeletal mesh component */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Weapon")
class USkeletalMeshComponent* WeaponMesh;

/** Weapon's skeletal mesh asset - SET THIS IN BLUEPRINT OR CODE */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon")
class USkeletalMesh* WeaponSkeletalMesh;

/** Weapon stats */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Stats")
float Damage = 25.0f;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Stats")
float FireRate = 0.1f;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Stats")
int32 MaxAmmo = 30;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Weapon Stats")
int32 CurrentAmmo;

/** Audio Effects */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio")
class USoundBase* FireSound;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio")
class USoundBase* ReloadSound;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio")
class USoundBase* EmptyClickSound;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Audio")
class USoundBase* WeaponDrawSound;

/** Visual Effects */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effects")
class UParticleSystem* MuzzleFlash;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effects")
class UParticleSystem* ShellEjection;

/** Weapon Animations */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations")
class UAnimationAsset* FireAnimation;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations")
class UAnimationAsset* ReloadAnimation;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations")
class UAnimationAsset* DrawAnimation;

/** Character Animations (First Person) */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Animations")
class UAnimationAsset* FP_FireAnimation;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Animations")
class UAnimationAsset* FP_ReloadAnimation;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Animations")
class UAnimationAsset* FP_DrawAnimation;

/** Fire timing */
UPROPERTY(BlueprintReadOnly, Category = "Weapon")
bool bCanFire = true;

UPROPERTY(BlueprintReadOnly, Category = "Weapon")
bool bIsReloading = false;

FTimerHandle FireRateTimerHandle;
FTimerHandle ReloadTimerHandle;

/** Reset fire rate limiter */
UFUNCTION()
void ResetFireRate();

/** Complete reload */
UFUNCTION()
void CompleteReload();

/** Play weapon animation */
void PlayWeaponAnimation(class UAnimationAsset* AnimToPlay);

/** Play character animation */
void PlayCharacterAnimation(class UAnimationAsset* AnimToPlay);

public:
/** Called when the game starts or when spawned */
virtual void BeginPlay() override;

/** Fire the weapon */
UFUNCTION(BlueprintCallable, Category = "Weapon")
virtual void Fire();

/** Reload the weapon */
UFUNCTION(BlueprintCallable, Category = "Weapon")
virtual void Reload();

/** Draw/Equip weapon */
UFUNCTION(BlueprintCallable, Category = "Weapon")
virtual void DrawWeapon();

/** Set weapon mesh - useful for setting mesh in code */
UFUNCTION(BlueprintCallable, Category = "Weapon")
void SetWeaponMesh(class USkeletalMesh* NewMesh);

/** Get weapon mesh */
UFUNCTION(BlueprintCallable, Category = "Weapon")
class USkeletalMeshComponent* GetWeaponMesh() const { return WeaponMesh; }

/** Get current ammo */
UFUNCTION(BlueprintCallable, Category = "Weapon")
int32 GetCurrentAmmo() const { return CurrentAmmo; }

/** Get max ammo */
UFUNCTION(BlueprintCallable, Category = "Weapon")
int32 GetMaxAmmo() const { return MaxAmmo; }

/** Check if weapon can fire */
UFUNCTION(BlueprintCallable, Category = "Weapon")
bool CanFire() const { return bCanFire && CurrentAmmo > 0 && !bIsReloading; }

/** Check if weapon is reloading */
UFUNCTION(BlueprintCallable, Category = "Weapon")
bool IsReloading() const { return bIsReloading; }
};

AWeaponBase.cpp

#include "AWeaponBase.h"
#include "Components/SkeletalMeshComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Particles/ParticleSystemComponent.h"
#include "Sound/SoundBase.h"
#include "Engine/World.h"
#include "TimerManager.h"
#include "Animation/AnimationAsset.h"
#include "GameFramework/Character.h"
#include "BodycamProjectCharacter.h"

AWeaponBase::AWeaponBase()
{
PrimaryActorTick.bCanEverTick = false;

// Create weapon mesh component as root component
WeaponMesh = CreateDefaultSubobject(TEXT("WeaponMesh"));
RootComponent = WeaponMesh;

// Initialize ammo
CurrentAmmo = MaxAmmo;

// Initialize mesh pointer
WeaponSkeletalMesh = nullptr;

}

void AWeaponBase::BeginPlay()
{
Super::BeginPlay();

// Set the mesh if it's assigned
if (WeaponSkeletalMesh && WeaponMesh)
{
WeaponMesh->SetSkeletalMesh(WeaponSkeletalMesh);
UE_LOG(LogTemp, Log, TEXT("Weapon mesh set successfully"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("WeaponSkeletalMesh is not assigned! Please set it in Blueprint or code"));
}
}

void AWeaponBase::SetWeaponMesh(USkeletalMesh* NewMesh)
{
WeaponSkeletalMesh = NewMesh;
if (WeaponMesh && WeaponSkeletalMesh)
{
WeaponMesh->SetSkeletalMesh(WeaponSkeletalMesh);
UE_LOG(LogTemp, Log, TEXT("Weapon mesh updated"));
}
}

void AWeaponBase::Fire()
{
// Check if we can fire
if (!CanFire())
{
// Play empty click sound
if (EmptyClickSound && CurrentAmmo DoesSocketExist(TEXT("MuzzleFlashSocket")) ?
WeaponMesh->GetSocketLocation(TEXT("MuzzleFlashSocket")) :
WeaponMesh->GetComponentLocation();

FRotator MuzzleRotation = WeaponMesh->DoesSocketExist(TEXT("MuzzleFlashSocket")) ?
WeaponMesh->GetSocketRotation(TEXT("MuzzleFlashSocket")) :
GetActorRotation();

UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), MuzzleFlash, MuzzleLocation, MuzzleRotation);
}

// Spawn shell ejection effect
if (ShellEjection && WeaponMesh)
{
FVector EjectionLocation = WeaponMesh->DoesSocketExist(TEXT("ShellEjectionSocket")) ?
WeaponMesh->GetSocketLocation(TEXT("ShellEjectionSocket")) :
WeaponMesh->GetComponentLocation();

UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ShellEjection, EjectionLocation, GetActorRotation());
}

// Perform raycast for hit detection
if (WeaponMesh)
{
FVector Start = WeaponMesh->DoesSocketExist(TEXT("MuzzleFlashSocket")) ?
WeaponMesh->GetSocketLocation(TEXT("MuzzleFlashSocket")) :
WeaponMesh->GetComponentLocation();

FVector ForwardVector = WeaponMesh->DoesSocketExist(TEXT("MuzzleFlashSocket")) ?
WeaponMesh->GetSocketRotation(TEXT("MuzzleFlashSocket")).Vector() :
GetActorForwardVector();

FVector End = Start + (ForwardVector * 10000.0f);

FHitResult HitResult;
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(this);
QueryParams.AddIgnoredActor(GetOwner());

bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Visibility, QueryParams);

if (bHit)
{
UE_LOG(LogTemp, Log, TEXT("Hit: %s at distance: %f"),
HitResult.GetActor() ? *HitResult.GetActor()->GetName() : TEXT("Unknown"),
FVector::Dist(Start, HitResult.Location));
}
}

// Set fire rate limiter
bCanFire = false;
GetWorldTimerManager().SetTimer(FireRateTimerHandle, this, &AWeaponBase::ResetFireRate, FireRate, false);
}

void AWeaponBase::Reload()
{
// Don't reload if already full or already reloading
if (CurrentAmmo >= MaxAmmo || bIsReloading)
{
return;
}

bIsReloading = true;
UE_LOG(LogTemp, Log, TEXT("Starting reload..."));

// Play reload sound
if (ReloadSound)
{
UGameplayStatics::PlaySoundAtLocation(this, ReloadSound, GetActorLocation());
}

// Play reload animations
PlayWeaponAnimation(ReloadAnimation);
PlayCharacterAnimation(FP_ReloadAnimation);

// Set timer for reload completion (adjust time based on your animation length)
float ReloadTime = 2.0f; // 2 seconds default, adjust as needed
GetWorldTimerManager().SetTimer(ReloadTimerHandle, this, &AWeaponBase::CompleteReload, ReloadTime, false);
}

void AWeaponBase::DrawWeapon()
{
UE_LOG(LogTemp, Log, TEXT("Drawing weapon"));

// Play draw sound
if (WeaponDrawSound)
{
UGameplayStatics::PlaySoundAtLocation(this, WeaponDrawSound, GetActorLocation());
}

// Play draw animations
PlayWeaponAnimation(DrawAnimation);
PlayCharacterAnimation(FP_DrawAnimation);
}

void AWeaponBase::PlayWeaponAnimation(UAnimationAsset* AnimToPlay)
{
if (AnimToPlay && WeaponMesh)
{
WeaponMesh->PlayAnimation(AnimToPlay, false);
}
}

void AWeaponBase::PlayCharacterAnimation(UAnimationAsset* AnimToPlay)
{
if (AnimToPlay)
{
// Get the character owner and cast to your specific character class
if (ABodycamProjectCharacter* OwnerCharacter = Cast(GetOwner()))
{
// Use the GetFirstPersonMesh function from your character
if (USkeletalMeshComponent* FPMesh = OwnerCharacter->GetFirstPersonMesh())
{
FPMesh->PlayAnimation(AnimToPlay, false);
}
}
}
}

void AWeaponBase::CompleteReload()
{
CurrentAmmo = MaxAmmo;
bIsReloading = false;
UE_LOG(LogTemp, Log, TEXT("Reload complete - Ammo: %d/%d"), CurrentAmmo, MaxAmmo);
}

void AWeaponBase::ResetFireRate()
{
bCanFire = true;
}


Подробнее здесь: https://stackoverflow.com/questions/796 ... ter-sprits
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»