From b5707ed88890f45de0cdd9d295e3d8a24a2f5c80 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 5 Apr 2023 21:44:55 -0700 Subject: [PATCH] Trying to find the modulo problem --- src/dawn/util/random.hpp | 3 ++- src/dawnrose/scene/components/entity/EntityAIWalk.cpp | 7 +++++-- src/dawnshared/util/mathutils.hpp | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/dawn/util/random.hpp b/src/dawn/util/random.hpp index fc55f99b..0d10da91 100644 --- a/src/dawn/util/random.hpp +++ b/src/dawn/util/random.hpp @@ -44,7 +44,8 @@ namespace Dawn { } static inline float_t randRange(float_t min, float_t max) { - return mathMod(randomGenerate(), (max - min)) + min; + float_t n = randomGenerate(); + return mathMod(n, (max - min)) + min; } static inline glm::vec2 randRange(glm::vec2 min, glm::vec2 max) { diff --git a/src/dawnrose/scene/components/entity/EntityAIWalk.cpp b/src/dawnrose/scene/components/entity/EntityAIWalk.cpp index 2c90af8d..b05cca38 100644 --- a/src/dawnrose/scene/components/entity/EntityAIWalk.cpp +++ b/src/dawnrose/scene/components/entity/EntityAIWalk.cpp @@ -25,9 +25,11 @@ void EntityAIWalk::onStart() { case ENTITY_AI_WALK_MODE_FOLLOW_TARGET: this->updateFollowTarget(delta); break; + case ENTITY_AI_WALK_MODE_WANDER: this->updateWander(delta); break; + case ENTITY_AI_WALK_MODE_STAY: this->entityMove->direction = glm::vec2(0, 0); break; @@ -48,8 +50,9 @@ void EntityAIWalk::updateWander(float_t delta) { wanderTimeToNextDecision = randRange(wanderTimeRandomRange.x, wanderTimeRandomRange.y); // Do we want to move? - if(randRange(0.0f, 1.0f) < wanderDoNotMoveChance) { - this->entityMove->direction = glm::vec2(0, 0); + float_t rr = randRange(0.0f, 3.0f); + if(rr < wanderDoNotMoveChance) { + wanderDestination = physics3Dto2D(transform->getLocalPosition()); return; } diff --git a/src/dawnshared/util/mathutils.hpp b/src/dawnshared/util/mathutils.hpp index bc280002..0951d285 100644 --- a/src/dawnshared/util/mathutils.hpp +++ b/src/dawnshared/util/mathutils.hpp @@ -74,7 +74,8 @@ namespace Dawn { } static inline float_t mathMod(float_t value, float_t modulo) { - return (float_t)fmod(value, modulo); + float_t n = fmod(value, modulo); + return n; } /**