Game Development

c++ – I wish to change the path of my platform from z path to y path alternatively

So mainly i would like my platform to maneuver first in z path like from begin place to finish place after which finish place to begin. now after reaching begin it ought to change its path y axis, it ought to do the identical, begin to finish and finish to begin after which change the path again to z. however i cant appear to do it. can anybody please inform me how am i able to do that. I’m new to these things in ue5.

// Units default values
AMovingPlatform::AMovingPlatform()
{
    // Set this actor to name Tick() each body.  You'll be able to flip this off to enhance efficiency in case you do not want it.
    PrimaryActorTick.bCanEverTick = true;
}
// Referred to as when the sport begins or when spawned
void AMovingPlatform::BeginPlay()
{
    Tremendous::BeginPlay();
    StartLocation = GetActorLocation();  
    
    UE_LOG(LogTemp, Show, TEXT("Hiya"));
}
// Referred to as each body
void AMovingPlatform::Tick(float DeltaTime)
{
    Tremendous::Tick(DeltaTime);  
    
    MovePlatform(DeltaTime);
    RotatePlatform(DeltaTime);
}
void AMovingPlatform::MovePlatform(float DeltaTime) {
    if (ShouldPlatformReturn()) {

        FVector MoveDirection = PlatformVelocity.GetSafeNormal();
        StartLocation = StartLocation + MoveDirection * MoveDistance;
        SetActorLocation(StartLocation);
        PlatformVelocity = -PlatformVelocity;     
    }   
    else {
        if (ShouldChangeDirection()) {
            PlatformVelocity = FVector(0, 600, 0); // Change path
            FVector MoveDirection = PlatformVelocity.GetSafeNormal();
            StartLocation = StartLocation + MoveDirection * MoveDistance;
            SetActorLocation(StartLocation);
            PlatformVelocity = -PlatformVelocity;

        }
        FVector CurrentLocation = GetActorLocation();
        CurrentLocation = CurrentLocation + (PlatformVelocity * DeltaTime);
        SetActorLocation(CurrentLocation);
    }   
}
void AMovingPlatform::RotatePlatform(float DeltaTime) {
    
    AddActorLocalRotation(RotationVelocity * DeltaTime);

}

bool AMovingPlatform::ShouldChangeDirection() const {
    

    float Epsilon = 10.0f; // Modify this worth to account for floating-point precision
    return GetDistanceMoved() > MoveDistance - Epsilon;
    //return StartLocation == GetActorLocation();
}

bool AMovingPlatform::ShouldPlatformReturn() const {
    return GetDistanceMoved() >= MoveDistance;
}

float AMovingPlatform :: GetDistanceMoved() const {

    return FVector::Dist(StartLocation, GetActorLocation());
}
// Fill out your copyright discover within the Description web page of Venture Settings.

#pragma as soon as

#embrace "CoreMinimal.h"
#embrace "GameFramework/Actor.h"
#embrace "MovingPlatform.generated.h"

UCLASS()
class FAKEFALLGUYS_API AMovingPlatform : public AActor
{
    GENERATED_BODY()
    
public: 
    // Units default values for this actor's properties
    AMovingPlatform();

protected:
    // Referred to as when the sport begins or when spawned
    digital void BeginPlay() override;

public: 
    // Referred to as each body
    digital void Tick(float DeltaTime) override;


    UPROPERTY(EditAnywhere, BlueprintReadWrite, Class="Shifting")
    FVector PlatformVelocity = FVector(0,0,500);

    UPROPERTY(EDITANYWHERE, BlueprintReadWrite, Class = "Shifting")
    float MoveDistance = 500;
    UPROPERTY(EDITANYWHERE, BlueprintReadWrite, Class = "Rotation")
    FRotator RotationVelocity;
    FVector StartLocation;

    UFUNCTION(BlueprintCallable)
        void MovePlatform(float DeltaTime);

    UFUNCTION(BlueprintCallable)
        void RotatePlatform(float DeltaTime);

    UFUNCTION(BlueprintCallable)
        bool ShouldPlatformReturn() const;

    UFUNCTION(BlueprintCallable)
        float GetDistanceMoved() const;

    UFUNCTION(BlueprintCallable)
        bool ShouldChangeDirection() const;
non-public:

};

About the author

Theme control panel

Leave a Comment