From daf5a7ffa99aa7400a433f358842a020d2af7447 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Tue, 22 Aug 2023 10:25:09 -0700 Subject: [PATCH] fixes --- .../ControllablePhysicsComponent.cpp | 11 +++++------ dGame/dComponents/MovementAIComponent.cpp | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/dGame/dComponents/ControllablePhysicsComponent.cpp b/dGame/dComponents/ControllablePhysicsComponent.cpp index 9c1d8975..cb367be0 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.cpp +++ b/dGame/dComponents/ControllablePhysicsComponent.cpp @@ -117,7 +117,10 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo } if (!bIsInitialUpdate) m_DirtyBubble = false; } - + + bool isVelocityZero = m_Velocity != NiPoint3::ZERO; + bool isAngularVelocityZero = m_AngularVelocity != NiPoint3::ZERO; + bool shouldWriteFrameStats = m_DirtyPosition || bIsInitialUpdate || isVelocityZero || isAngularVelocityZero; outBitStream->Write(m_DirtyPosition || bIsInitialUpdate); if (m_DirtyPosition || bIsInitialUpdate) { outBitStream->Write(m_Position.x); @@ -132,7 +135,6 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo outBitStream->Write(m_IsOnGround); outBitStream->Write(m_IsOnRail); - bool isVelocityZero = m_Velocity != NiPoint3::ZERO; outBitStream->Write(isVelocityZero); if (isVelocityZero) { outBitStream->Write(m_Velocity.x); @@ -140,7 +142,6 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo outBitStream->Write(m_Velocity.z); } - bool isAngularVelocityZero = m_AngularVelocity != NiPoint3::ZERO; outBitStream->Write(isAngularVelocityZero); if (isAngularVelocityZero) { outBitStream->Write(m_AngularVelocity.x); @@ -202,9 +203,7 @@ void ControllablePhysicsComponent::SetPosition(const NiPoint3& pos) { return; } - m_Position.x = pos.x; - m_Position.y = pos.y; - m_Position.z = pos.z; + m_Position = pos; m_DirtyPosition = true; if (m_dpEntity) m_dpEntity->SetPosition(pos); diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index 05063862..ff8aff33 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -143,11 +143,11 @@ void MovementAIComponent::Update(const float deltaTime) { return; } - // if (m_CurrentSpeed < m_MaxSpeed) { - // m_CurrentSpeed += m_Acceleration; - // } - if (m_CurrentSpeed < m_MaxSpeed) { + m_CurrentSpeed += m_Acceleration; + } + + if (m_CurrentSpeed > m_MaxSpeed) { m_CurrentSpeed = m_MaxSpeed; } @@ -221,10 +221,15 @@ NiPoint3 MovementAIComponent::GetCurrentWaypoint() const { NiPoint3 MovementAIComponent::ApproximateLocation() const { auto source = m_Parent->GetPosition(); if (AtFinalWaypoint()) return source; + NiPoint3 approximation = source; + + // Only have physics sim for controllable physics + if (!m_Parent->HasComponent(ControllablePhysicsComponent::ComponentType)) { + auto destination = GetNextWaypoint(); + auto percentageToWaypoint = m_TimeToTravel > 0 ? m_TimeTravelled / m_TimeToTravel : 0; + approximation = source + ((destination - source) * percentageToWaypoint); + } - auto destination = GetNextWaypoint(); - auto percentageToWaypoint = m_TimeToTravel > 0 ? m_TimeTravelled / m_TimeToTravel : 0; - auto approximation = source + ((destination - source) * percentageToWaypoint); if (dpWorld::Instance().IsLoaded()) { approximation.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(approximation); }