From 88a29f2770fbd2ff5a32d0afd35acc98b4d38a99 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 27 Jul 2022 20:08:17 +0200 Subject: [PATCH] Improve crowd speed/acceleration/braking Changed to values comparable to game. Added sliders for acceleration and speed. --- r5dev/naveditor/CrowdTool.cpp | 26 ++++++++++++++----- r5dev/naveditor/include/CrowdTool.h | 3 +++ .../recast/DetourCrowd/Source/DetourCrowd.cpp | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/r5dev/naveditor/CrowdTool.cpp b/r5dev/naveditor/CrowdTool.cpp index f6fba6fe..d0ed6f2f 100644 --- a/r5dev/naveditor/CrowdTool.cpp +++ b/r5dev/naveditor/CrowdTool.cpp @@ -105,8 +105,10 @@ CrowdToolState::CrowdToolState() : m_toolParams.m_optimizeTopo = true; m_toolParams.m_obstacleAvoidance = true; m_toolParams.m_obstacleAvoidanceType = 3.0f; - m_toolParams.m_separation = false; - m_toolParams.m_separationWeight = 2.0f; + m_toolParams.m_separation = true; + m_toolParams.m_separationWeight = 20.0f; + m_toolParams.m_maxAcceleration = 800.f; + m_toolParams.m_maxSpeed = 200.f; memset(m_trails, 0, sizeof(m_trails)); @@ -630,10 +632,10 @@ void CrowdToolState::addAgent(const float* p) memset(&ap, 0, sizeof(ap)); ap.radius = m_sample->getAgentRadius(); ap.height = m_sample->getAgentHeight(); - ap.maxAcceleration = 8.0f; - ap.maxSpeed = 3.5f; - ap.collisionQueryRange = ap.radius * 12.0f; - ap.pathOptimizationRange = ap.radius * 30.0f; + ap.maxAcceleration = m_toolParams.m_maxAcceleration; + ap.maxSpeed = m_toolParams.m_maxSpeed; + ap.collisionQueryRange = ap.radius * 50.0f; + ap.pathOptimizationRange = ap.radius * 300.0f; ap.updateFlags = 0; if (m_toolParams.m_anticipateTurns) ap.updateFlags |= DT_CROWD_ANTICIPATE_TURNS; @@ -804,6 +806,8 @@ void CrowdToolState::updateAgentParams() params.updateFlags = updateFlags; params.obstacleAvoidanceType = obstacleAvoidanceType; params.separationWeight = m_toolParams.m_separationWeight; + params.maxAcceleration = m_toolParams.m_maxAcceleration; + params.maxSpeed = m_toolParams.m_maxSpeed; crowd->updateAgentParameters(i, ¶ms); } } @@ -924,7 +928,15 @@ void CrowdTool::handleMenu() params->m_separation = !params->m_separation; m_state->updateAgentParams(); } - if (imguiSlider("Separation Weight", ¶ms->m_separationWeight, 0.0f, 20.0f, 0.01f)) + if (imguiSlider("Separation Weight", ¶ms->m_separationWeight, 0.0f, 200.0f, 0.01f)) + { + m_state->updateAgentParams(); + } + if (imguiSlider("Max Acceleration", ¶ms->m_maxAcceleration, 0.0f, 2000.0f, 0.01f)) + { + m_state->updateAgentParams(); + } + if (imguiSlider("Max Speed", ¶ms->m_maxSpeed, 0.0f, 2000.0f, 0.01f)) { m_state->updateAgentParams(); } diff --git a/r5dev/naveditor/include/CrowdTool.h b/r5dev/naveditor/include/CrowdTool.h index d10b6533..0b327a8f 100644 --- a/r5dev/naveditor/include/CrowdTool.h +++ b/r5dev/naveditor/include/CrowdTool.h @@ -52,6 +52,9 @@ struct CrowdToolParams float m_obstacleAvoidanceType; bool m_separation; float m_separationWeight; + + float m_maxAcceleration; + float m_maxSpeed; }; class CrowdToolState : public SampleToolState diff --git a/r5dev/thirdparty/recast/DetourCrowd/Source/DetourCrowd.cpp b/r5dev/thirdparty/recast/DetourCrowd/Source/DetourCrowd.cpp index 329493c4..d487259a 100644 --- a/r5dev/thirdparty/recast/DetourCrowd/Source/DetourCrowd.cpp +++ b/r5dev/thirdparty/recast/DetourCrowd/Source/DetourCrowd.cpp @@ -1200,7 +1200,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug) calcStraightSteerDirection(ag, dvel); // Calculate speed scale, which tells the agent to slowdown at the end of the path. - const float slowDownRadius = ag->params.radius*2; // TODO: make less hacky. + const float slowDownRadius = ag->params.radius*4; // TODO: make less hacky. const float speedScale = getDistanceToGoal(ag, slowDownRadius) / slowDownRadius; ag->desiredSpeed = ag->params.maxSpeed;