-
Notifications
You must be signed in to change notification settings - Fork 235
Open
Description
The code tries to compensate client and server's different scrolling time by multiplying a compensation ratio defined by currentViewPosition / currentWorldPosition. Then it multiplies the ratio by speed to get a more appropriate speed.
There are a problem with this approach:
The farther away from the goal, the less impact the compensation ratio makes (4010/4000 vs 20/10 even though both have 10 units difference)
Compensation=1.0+(Error×Constant) should be used for equal impact throughout where Error is (Server - Client)
This compensation should also be multipled to each aircraft's velocity to prevent it from continuously drifting.
void World::adaptPlayerVelocity()
{
for (Aircraft* aircraft : mPlayerAircrafts)
{
sf::Vector2f velocity = aircraft->getVelocity();
if (velocity.x != 0.f && velocity.y != 0.f)
{
aircraft->setVelocity(velocity / sqrtf(2.f));
}
aircraft->accelerate({ 0.f, mScrollSpeed * mScrollSpeedCompensation });
}
}
Metadata
Metadata
Assignees
Labels
No labels