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

use constantly seeded random

parent 2a4afd1e
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
#include "DrawDebugHelpers.h" #include "DrawDebugHelpers.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
UPredictive::UPredictive()
{
RandomStream = FRandomStream(0);
}
/** /**
* Implementation based on the following paper: * Implementation based on the following paper:
* Karamouzas et al.: * Karamouzas et al.:
...@@ -186,8 +191,8 @@ void UPredictive::PostProcessVelocity(float LastDeltaTime, FVector& Velocity) ...@@ -186,8 +191,8 @@ void UPredictive::PostProcessVelocity(float LastDeltaTime, FVector& Velocity)
/************************************************************************/ /************************************************************************/
/* NOISE TO AVOID DEADLOCKS AND INTRODUCE VARIATIONS */ /* NOISE TO AVOID DEADLOCKS AND INTRODUCE VARIATIONS */
/************************************************************************/ /************************************************************************/
float angle = FMath::RandRange(0.0f, 2.0f * PI); float angle = RandomStream.FRandRange(0.0f, 2.0f * PI);
float dist = FMath::RandRange(0.0f, 0.001f); float dist = RandomStream.FRandRange(0.0f, 0.001f);
force += dist * FVector2D(cos(angle), sin(angle)); force += dist * FVector2D(cos(angle), sin(angle));
// Cap the force to maxAcceleration // Cap the force to maxAcceleration
......
...@@ -31,6 +31,8 @@ UVHMovement::UVHMovement() ...@@ -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 // 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. // off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bCanEverTick = true;
RandomStream = FRandomStream(0);
} }
...@@ -402,8 +404,7 @@ TArray<AWaypoint*> UVHMovement::ShuffleArray(TArray<AWaypoint*> myArray) ...@@ -402,8 +404,7 @@ TArray<AWaypoint*> UVHMovement::ShuffleArray(TArray<AWaypoint*> myArray)
int32 LastIndex = myArray.Num() - 1; int32 LastIndex = myArray.Num() - 1;
for (int32 i = 0; i <= LastIndex; ++i) for (int32 i = 0; i <= LastIndex; ++i)
{ {
srand(time(0)-i); int32 Index = RandomStream.FRandRange(0,LastIndex);
int32 Index = rand() % LastIndex;
if (i != Index) if (i != Index)
{ {
myArray.Swap(Index, i); myArray.Swap(Index, i);
......
...@@ -16,6 +16,8 @@ class CHARACTERPLUGIN_API UPredictive : public UVelocityPostProcessorComponent ...@@ -16,6 +16,8 @@ class CHARACTERPLUGIN_API UPredictive : public UVelocityPostProcessorComponent
GENERATED_BODY() GENERATED_BODY()
public: public:
UPredictive();
virtual void PostProcessVelocity(float LastDeltaTime, FVector& Velocity) override; virtual void PostProcessVelocity(float LastDeltaTime, FVector& Velocity) override;
// These following values come directly from the Karamouzas paper (see cpp) // These following values come directly from the Karamouzas paper (see cpp)
...@@ -63,4 +65,6 @@ public: ...@@ -63,4 +65,6 @@ public:
private: private:
float RayCircleTTC(const FVector2D& Dir, const FVector2D& Center, float Radius); float RayCircleTTC(const FVector2D& Dir, const FVector2D& Center, float Radius);
FRandomStream RandomStream;
}; };
...@@ -181,4 +181,6 @@ private: ...@@ -181,4 +181,6 @@ private:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void WaypointMovement(); 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