Skip to content
Snippets Groups Projects
Commit e7eaefa0 authored by Ehret's avatar Ehret
Browse files

use constantly seeded random

parent 2a4afd1e
Branches feature/study
No related tags found
No related merge requests found
......@@ -11,6 +11,11 @@
#include "DrawDebugHelpers.h"
#include "Kismet/GameplayStatics.h"
UPredictive::UPredictive()
{
RandomStream = FRandomStream(0);
}
/**
* Implementation based on the following paper:
* Karamouzas et al.:
......@@ -186,8 +191,8 @@ void UPredictive::PostProcessVelocity(float LastDeltaTime, FVector& Velocity)
/************************************************************************/
/* NOISE TO AVOID DEADLOCKS AND INTRODUCE VARIATIONS */
/************************************************************************/
float angle = FMath::RandRange(0.0f, 2.0f * PI);
float dist = FMath::RandRange(0.0f, 0.001f);
float angle = RandomStream.FRandRange(0.0f, 2.0f * PI);
float dist = RandomStream.FRandRange(0.0f, 0.001f);
force += dist * FVector2D(cos(angle), sin(angle));
// Cap the force to maxAcceleration
......
......@@ -31,6 +31,8 @@ UVHMovement::UVHMovement()
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
RandomStream = FRandomStream(0);
}
......@@ -402,8 +404,7 @@ TArray<AWaypoint*> UVHMovement::ShuffleArray(TArray<AWaypoint*> myArray)
int32 LastIndex = myArray.Num() - 1;
for (int32 i = 0; i <= LastIndex; ++i)
{
srand(time(0)-i);
int32 Index = rand() % LastIndex;
int32 Index = RandomStream.FRandRange(0,LastIndex);
if (i != Index)
{
myArray.Swap(Index, i);
......
......@@ -16,6 +16,8 @@ class CHARACTERPLUGIN_API UPredictive : public UVelocityPostProcessorComponent
GENERATED_BODY()
public:
UPredictive();
virtual void PostProcessVelocity(float LastDeltaTime, FVector& Velocity) override;
// These following values come directly from the Karamouzas paper (see cpp)
......@@ -63,4 +65,6 @@ public:
private:
float RayCircleTTC(const FVector2D& Dir, const FVector2D& Center, float Radius);
FRandomStream RandomStream;
};
......@@ -181,4 +181,6 @@ private:
UFUNCTION(BlueprintCallable)
void WaypointMovement();
FRandomStream RandomStream;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment