Prevent the character to go out of bound in animation viewport (#7667)

* Prevent the character to go out of bound

Signed-off-by: rhhong <rhhong@amazon.com>

* CR feedback

Signed-off-by: rhhong <rhhong@amazon.com>
development
Roman 4 years ago committed by GitHub
parent 7de6bc5b23
commit 464b225042
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -224,6 +224,22 @@ namespace EMStudio
return m_entityContext->GetContextId();
}
void AnimViewportRenderer::CheckBounds()
{
AZ::Vector3 groundPos;
AZ::TransformBus::EventResult(groundPos, m_groundEntity->GetId(), &AZ::TransformBus::Events::GetWorldTranslation);
const AZ::Vector3 characterPos = GetCharacterCenter();
if (AZStd::abs(characterPos.GetX() - groundPos.GetX()) > BoundMaxDistance ||
AZStd::abs(characterPos.GetY() - groundPos.GetY()) > BoundMaxDistance)
{
const float tileOffsetX = AZStd::fmod(characterPos.GetX(), TileSize);
const float tileOffsetY = AZStd::fmod(characterPos.GetX(), TileSize);
const AZ::Vector3 newGroundPos(characterPos.GetX() - tileOffsetX, characterPos.GetY() - tileOffsetY, groundPos.GetZ());
AZ::TransformBus::Event(m_groundEntity->GetId(), &AZ::TransformBus::Events::SetWorldTranslation, newGroundPos);
}
}
void AnimViewportRenderer::ResetEnvironment()
{
// Reset environment

@ -59,6 +59,9 @@ namespace EMStudio
AZ::EntityId GetEntityId() const;
AzFramework::EntityContextId GetEntityContextId() const;
// Call this function on update to prevent the character going out of bounds of the ground.
void CheckBounds();
private:
// This function resets the light, camera and other environment settings.
@ -91,6 +94,8 @@ namespace EMStudio
const RenderOptions* m_renderOptions;
const float DefaultFrustumDimension = 128.0f;
const float BoundMaxDistance = 150.0f;
const float TileSize = 1.0f;
AZStd::vector<AZ::Render::DirectionalLightFeatureProcessorInterface::LightHandle> m_lightHandles;
};
}

@ -206,6 +206,7 @@ namespace EMStudio
CalculateCameraProjection();
RenderCustomPluginData();
FollowCharacter();
m_renderer->CheckBounds();
}
void AnimViewportWidget::CalculateCameraProjection()

Loading…
Cancel
Save