Skip to content

Commit

Permalink
Fixed negative value of speed (#501)
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Budziszewski <pawel.budziszewski@robotec.ai>
Co-authored-by: Michał Pełka <michal.pelka@robotec.ai>
Signed-off-by: Michał Pełka <michal.pelka@robotec.ai>
  • Loading branch information
pawelbudziszewski and michalpelka committed Oct 3, 2023
1 parent e9b835c commit 9835ecc
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace WarehouseAutomation
// initial segment population
AZ_Assert(m_splineLength != 0.0f, "m_splineLength must be non-zero");
const float normalizedDistanceStep = SegmentSeparation * m_configuration.m_segmentSize / m_splineLength;
for (float normalizedIndex = 0.f; normalizedIndex < 1.f; normalizedIndex += normalizedDistanceStep)
for (float normalizedIndex = 0.f; normalizedIndex < 1.f + normalizedDistanceStep; normalizedIndex += normalizedDistanceStep)
{
m_conveyorSegments.push_back(CreateSegment(splinePtr, normalizedIndex));
}
Expand Down Expand Up @@ -278,7 +278,8 @@ namespace WarehouseAutomation
bool wasSegmentRemoved = false;
for (auto& [pos, handle] : m_conveyorSegments)
{
if (pos > 1.0f)
const bool positiveDirection = m_configuration.m_speed > 0.0f;
if ((positiveDirection && pos > 1.0f) || (!positiveDirection && pos < 0.0f))
{
AZ::Interface<AzPhysics::SceneInterface>::Get()->RemoveSimulatedBody(m_sceneHandle, handle);
handle = AzPhysics::InvalidSimulatedBodyHandle;
Expand Down Expand Up @@ -322,16 +323,18 @@ namespace WarehouseAutomation

void ConveyorBeltComponent::SpawnSegments(float deltaTime)
{
// Find normalized spawn place (0.0 or 1.0) depending on movement direction
const float spawnPlaceNormalized = static_cast<float>(m_configuration.m_speed<0.0f);
m_deltaTimeFromLastSpawn += deltaTime;
if (m_conveyorSegments.empty())
{
m_conveyorSegments.push_back(CreateSegment(m_splineConsPtr, 0.f));
m_conveyorSegments.push_back(CreateSegment(m_splineConsPtr, spawnPlaceNormalized));
return;
}
if (m_deltaTimeFromLastSpawn > SegmentSeparation * m_configuration.m_segmentSize / m_configuration.m_speed)
if (m_deltaTimeFromLastSpawn > SegmentSeparation * m_configuration.m_segmentSize / AZStd::abs(m_configuration.m_speed))
{
m_deltaTimeFromLastSpawn = 0.f;
m_conveyorSegments.push_back(CreateSegment(m_splineConsPtr, 0.f));
m_conveyorSegments.push_back(CreateSegment(m_splineConsPtr, spawnPlaceNormalized));
}
}

Expand Down

0 comments on commit 9835ecc

Please sign in to comment.