MovingActor nun auch auf Z Achse, auch zurück nun möglich
This commit is contained in:
parent
5b798d4f3b
commit
68973fb6f6
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -15,28 +15,56 @@ void UMovingActor::BeginPlay()
|
|||
|
||||
void UMovingActor::Move()
|
||||
{
|
||||
if(moving) return;
|
||||
UE_LOG(LogTemp, Warning, TEXT("start"))
|
||||
targetLocation = GetOwner()->GetActorLocation();
|
||||
if(!Negative && !Up)
|
||||
{
|
||||
this->targetLocation.X += MovementTarget;
|
||||
this->tempLocation = FVector(MovementSpeed, 0.0f, 0.0f);
|
||||
}
|
||||
if (Negative)
|
||||
{
|
||||
targetLocation.Y += MovementTarget;
|
||||
tempLocation = FVector(0.0f, MovementSpeed, 0.0f);
|
||||
}
|
||||
if(!Negative)
|
||||
{
|
||||
targetLocation.X += MovementTarget;
|
||||
tempLocation = FVector(MovementSpeed, 0.0f, 0.0f);
|
||||
this->targetLocation.Y += MovementTarget;
|
||||
this->tempLocation = FVector(0.0f, MovementSpeed, 0.0f);
|
||||
}
|
||||
if(Up)
|
||||
{
|
||||
targetLocation.Z += MovementTarget;
|
||||
tempLocation = FVector(0.0f, 0.0f, MovementSpeed);
|
||||
this->targetLocation.Z += MovementTarget;
|
||||
this->tempLocation = FVector(0.0f, 0.0f, MovementSpeed);
|
||||
|
||||
}
|
||||
this->targetLocation = targetLocation;
|
||||
this->moving = true;
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("%f %f %f"), targetLocation.X, targetLocation.Y, targetLocation.Z)
|
||||
UE_LOG(LogTemp, Warning, TEXT("%f"), MovementSpeed)
|
||||
PlaySound();
|
||||
}
|
||||
|
||||
void UMovingActor::MoveBack()
|
||||
{
|
||||
if(moving) return;
|
||||
this->targetLocation = GetOwner()->GetActorLocation();
|
||||
if(!Negative && !Up)
|
||||
{
|
||||
this->targetLocation.X -= MovementTarget;
|
||||
this->tempLocation = FVector(-MovementSpeed, 0.0f, 0.0f);
|
||||
}
|
||||
if (Negative)
|
||||
{
|
||||
this->targetLocation.Y -= MovementTarget;
|
||||
this->tempLocation = FVector(0.0f, -MovementSpeed, 0.0f);
|
||||
}
|
||||
if(Up)
|
||||
{
|
||||
this->targetLocation.Z -= MovementTarget;
|
||||
this->tempLocation = FVector(0.0f, 0.0f, -MovementSpeed);
|
||||
|
||||
}
|
||||
this->moving = true;
|
||||
PlaySound();
|
||||
}
|
||||
|
||||
void UMovingActor::PlaySound()
|
||||
{
|
||||
TArray<UAudioComponent*> Audios;
|
||||
GetOwner()->GetComponents<UAudioComponent>(Audios);
|
||||
|
||||
|
@ -48,8 +76,8 @@ void UMovingActor::Move()
|
|||
if (Audio->ComponentHasTag("location"))
|
||||
{
|
||||
UGameplayStatics::PlaySoundAtLocation(GetOwner(), Audio->Sound, GetOwner()->GetActorLocation(),
|
||||
GetOwner()->GetActorRotation(), 1, 1, 0,
|
||||
Audio->AttenuationSettings, nullptr, GetOwner());
|
||||
GetOwner()->GetActorRotation(), 1, 1, 0,
|
||||
Audio->AttenuationSettings, nullptr, GetOwner());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -59,7 +87,6 @@ void UMovingActor::Move()
|
|||
soundHasBeenPlayed = true;
|
||||
}
|
||||
|
||||
|
||||
void UMovingActor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||
{
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
@ -67,7 +94,7 @@ void UMovingActor::TickComponent(float DeltaTime, ELevelTick TickType, FActorCom
|
|||
if (moving)
|
||||
{
|
||||
FVector Location = GetOwner()->GetActorLocation();
|
||||
if (Location.Equals(targetLocation, 1.0f))
|
||||
if (Location.Equals(targetLocation, 5.0f))
|
||||
{
|
||||
moving = false;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@ protected:
|
|||
UFUNCTION(BlueprintCallable)
|
||||
void Move();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void MoveBack();
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
|
||||
|
@ -40,8 +43,10 @@ public:
|
|||
bool Up = false;
|
||||
|
||||
private:
|
||||
bool moving;
|
||||
bool moving = false;
|
||||
bool soundHasBeenPlayed;
|
||||
FVector targetLocation;
|
||||
FVector tempLocation;
|
||||
|
||||
void PlaySound();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue