This commit is contained in:
David Markowitz 2023-08-22 10:25:09 -07:00
parent 67cd990d98
commit daf5a7ffa9
2 changed files with 17 additions and 13 deletions

View File

@ -118,6 +118,9 @@ 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);

View File

@ -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;
auto approximation = source + ((destination - source) * percentageToWaypoint);
approximation = source + ((destination - source) * percentageToWaypoint);
}
if (dpWorld::Instance().IsLoaded()) {
approximation.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(approximation);
}