UnrealScripterAI
Discord ↗
Link Copied to Clipboard
×
"create an advanced hot air balloon"
//HotAirBalloon Class Declaration #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "HotAirBalloon.generated.h" UCLASS() class EXAMPLEPROJECT_API AHotAirBalloon : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties AHotAirBalloon(); // Called every frame virtual void Tick(float DeltaTime) override; // Reference to the hot air balloon mesh component UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Hot Air Balloon") UStaticMeshComponent* BalloonMesh; // Reference to the hot air balloon particle system component UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Hot Air Balloon") UParticleSystemComponent* FlameParticles; // Maximum height that the hot air balloon can reach UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hot Air Balloon") float MaxHeight; // Speed at which the hot air balloon ascends and descends UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hot Air Balloon") float VerticalSpeed; private: // Private variables for handling the hot air balloon's movement float CurrentHeight; bool bIsAscending; }; //HotAirBalloon Class Implementation #include "HotAirBalloon.h" // Sets default values AHotAirBalloon::AHotAirBalloon() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; // Create and attach the hot air balloon mesh component BalloonMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BalloonMesh")); RootComponent = BalloonMesh; // Create and attach the hot air balloon particle system component FlameParticles = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("FlameParticles")); FlameParticles->SetupAttachment(RootComponent); // Initialize variables MaxHeight = 1000.0f; VerticalSpeed = 50.0f; CurrentHeight = GetActorLocation().Z; bIsAscending = true; } // Called every frame void AHotAirBalloon::Tick(float DeltaTime) { Super::Tick(DeltaTime); // Get the current location of the hot air balloon FVector CurrentLocation = GetActorLocation(); // If the hot air balloon is ascending, increase its height if (bIsAscending) { CurrentHeight = VerticalSpeed * DeltaTime; if (CurrentHeight >= MaxHeight) { bIsA }}}