diff --git a/Source/CharacterPlugin/Private/Crowds/Predictive.cpp b/Source/CharacterPlugin/Private/Crowds/Predictive.cpp index 1235752e096a4fbf0b9baae8634065f6012efb72..b79d876530bc75c5ec8426a175435758c14a9f10 100644 --- a/Source/CharacterPlugin/Private/Crowds/Predictive.cpp +++ b/Source/CharacterPlugin/Private/Crowds/Predictive.cpp @@ -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 diff --git a/Source/CharacterPlugin/Private/VHMovement.cpp b/Source/CharacterPlugin/Private/VHMovement.cpp index 5847eff42478f2bd924642bb1e0688eff1380994..7a05bfd18191f24bb3ad68d45930fda644ceed69 100644 --- a/Source/CharacterPlugin/Private/VHMovement.cpp +++ b/Source/CharacterPlugin/Private/VHMovement.cpp @@ -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); diff --git a/Source/CharacterPlugin/Public/Crowds/Predictive.h b/Source/CharacterPlugin/Public/Crowds/Predictive.h index 38a504f152660e8fcddc08c87ec1b0731f9913d9..ca6cdb559c01f7a943ac2deb720ebeb4403c116b 100644 --- a/Source/CharacterPlugin/Public/Crowds/Predictive.h +++ b/Source/CharacterPlugin/Public/Crowds/Predictive.h @@ -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; }; diff --git a/Source/CharacterPlugin/Public/VHMovement.h b/Source/CharacterPlugin/Public/VHMovement.h index 617343bee483acb0765948bc61994f68413e826a..06de023f4740f3d6e90018cb53ef0b644e0283c6 100644 --- a/Source/CharacterPlugin/Public/VHMovement.h +++ b/Source/CharacterPlugin/Public/VHMovement.h @@ -181,4 +181,6 @@ private: UFUNCTION(BlueprintCallable) void WaypointMovement(); + FRandomStream RandomStream; + };