give me a ue5 script of taming pets like game in ark survival
- User
give me a ue5 script of taming pets like game in ark survival
- Assistant
Here's an example script for taming pets in a game similar to Ark Survival using Unreal Engine 5:
#include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "TameablePet.h" #include "PlayerCharacter.h" ATameablePet::ATameablePet() { PrimaryActorTick.bCanEverTick = true; TamingProgress = 0.0f; bIsTaming = false; TamingTime = 5.0f; } void ATameablePet::BeginPlay() { Super::BeginPlay(); // Bind overlap function to the OnActorBeginOverlap event OnActorBeginOverlap.AddDynamic(this, &ATameablePet::OnTamingZoneOverlap); } void ATameablePet::Tick(float DeltaTime) { Super::Tick(DeltaTime); if (bIsTaming) { TamingProgress += DeltaTime; if (TamingProgress >= TamingTime) { Tame(); } } } void ATameablePet::OnTamingZoneOverlap(AActor* OverlappedActor, AActor* OtherActor) { APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor); if (PlayerCharacter) { StartTaming(); } } void ATameablePet::StartTaming() { bIsTaming = true; } void ATameablePet::Tame() { bIsTaming = false; OnTamed.Broadcast(); // Add the pet to the player's inventory or assign it as a companion, etc. }