Jump to content
  • Advertisement
Sign in to follow this  

Am I doing the interpolation correctly?

This topic is 1782 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to implement network entity interpolation described in this article: http://www.gabrielgambetta.com/fpm3.html


so far I have this and the circle's movement looks jittery. What did I do wrong?

struct Circle
	sf::Vector2f current;
	sf::Vector2f last;
	sf::CircleShape shape;
	void interpolate()
		sf::Vector2f difference = current - last;
		current.x += difference.x * 0.1;
		current.y += difference.y * 0.1;
	void draw(sf::RenderWindow & window)
		shape.setPosition(current.x, current.y);
	void setPosition(sf::Vector2f v)
		last = current;
		current = v;

void server()
	sf::TcpListener listener;
	sf::TcpSocket client;


	Circle circle;
	sf::RenderWindow window(sf::VideoMode(800, 600), "server");

	sf::Clock clock;
	sf::Time elapsed = sf::Time::Zero;
	sf::Time timePerFrame = sf::seconds(1 / 20.f);

	while (window.isOpen())
		sf::Time dt = clock.restart();
		elapsed += dt;
		while (elapsed > timePerFrame)
			elapsed -= timePerFrame;
			sf::Event event;
			while (window.pollEvent(event))
				if (event.type == sf::Event::Closed)

			sf::Packet packet;
			sf::Socket::Status s = client.receive(packet);
			while (s == sf::Socket::Done)
				//new position sent from the client;
				float x, y;
				packet >> x >> y;
				circle.setPosition({ x, y });
				s = client.receive(packet);


what's wrong with my code?


Share this post

Link to post
Share on other sites

Are you interpolating on the server? I would think you really only need to interpolate on the clients. Looks like you have the clients having authority over their positions. So the server gets their positions and just snaps to that position. I don't see anything wrong with snapping on the server side. It's when the server sends it's snapshots to the clients, the clients will want to interpolate between the last snapshot's so the movement seems visually smooth to the client. The server doesn't really care if the movement is smooth or not.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!