MovingPlatform.cpp
unknown
c_cpp
3 years ago
1.0 kB
10
Indexable
// Fill out your copyright notice in the Description page of Project Settings.
#include "MovingPlatform.h"
// Sets default values
AMovingPlatform::AMovingPlatform()
{
// 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;
}
// Called when the game starts or when spawned
void AMovingPlatform::BeginPlay()
{
Super::BeginPlay();
OriginalLocation = GetActorLocation();
}
// Called every frame
void AMovingPlatform::Tick(float DeltaTime)
{
FVector CurrentLocation = GetActorLocation() + (PlatformVelocity * DeltaTime);
SetActorLocation(CurrentLocation);
double Distance = FVector::Dist(CurrentLocation, OriginalLocation);
if(Distance > MoveDistance) {
FVector MoveDirection = PlatformVelocity.GetSafeNormal();
OriginalLocation = OriginalLocation + MoveDirection * MoveDistance;
SetActorLocation(OriginalLocation);
PlatformVelocity = -PlatformVelocity;
}
}
Editor is loading...