Skip to content

Ch 10. View Scrolling Compensation and Aircraft Scrolling Compensation #18

Description

@kyuhyunp

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions