Okay so I solved it by doing the following:
I added the following to the .h
file
APlateUp();
UPROPERTY(EditAnywhere)
UShapeComponent* Root;
UPROPERTY(EditAnywhere)
UStaticMeshComponent* MyMesh;
float RunningTime;
in the class public
And then in the .cpp
file I added
Root = CreateDefaultSubobject<UBoxComponent>(TEXT("Root"));
RootComponent = Root;
MyMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyMesh"));
MyMesh->AttachTo(RootComponent);
in the main function and then I added
FVector NewLocation = GetActorLocation();
float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
NewLocation.Z += DeltaHeight * 200.0f;
RunningTime += DeltaTime;
SetActorLocation(NewLocation);
Of course you can change the NewLocation.Z
to X or Y and you can change the force of which the object moves with.
These solutions were provided by watching Reuben Ward on YouTube so more explanation on all of this there. I'm just answering my question so if anyone ever has the same issue they can get the answer easily. Also, if you want to stop the object at a certain location you can do:
if (NewLocation.Z < 7700.0) {
float DeltaHeight = ((RunningTime + DeltaTime) - (RunningTime));
NewLocation.Z += DeltaHeight * 100.0f;
RunningTime += DeltaTime;
SetActorLocation(NewLocation);
}
And of course change the NewLocation.Z
to X or Y and the 7700.0
to whatever location you want on that axis. This checks if the current new location is less than the value you provide and if so it keeps moving the object on the axis. This is out of my own so if you have a question about this function specifically, feel free.