Hello, I already know how to program, so i wanted to take a look at C++ programming on the Unreal Engine. I started with the documentation, and there was a thing, that makes me pensive.
Here is the code, which i found in the Unreal Engine Documentation:
FloatingActor.h:
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/Actor.h"
#include "FloatingActor.generated.h"
UCLASS()
class QUICKSTART_API AFloatingActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AFloatingActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
float RunningTime;
};
FloatingActor.cpp:
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "QuickStart.h"
#include "FloatingActor.h"
// Sets default values
AFloatingActor::AFloatingActor()
{
// 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 AFloatingActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AFloatingActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
FVector NewLocation = GetActorLocation();
float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
NewLocation.Z += DeltaHeight * 20.0f; //Scale our height by a factor of 20
RunningTime += DeltaTime;
SetActorLocation(NewLocation);
}
So, i understand everything here, but one thing seems stupid to me.
There is the float “Running Time” and the code increases the float every tick. After a amount of Time, the highest possible number of the float should be reached and this will make an error, right?
Is there a better solution?
Btw, sorry for my bad english