Jump to content
  • Advertisement
Sign in to follow this  

Time Based Movement

This topic is 3518 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

Hey, I'm working on a RTS with a friend and we are having some issues with time based movement; notably, units move slower at lower FPS than at higher FPS. We do have a system for calculating the speed that a unit is traveling based on elapsed time, but it generally returns the same results, no matter the FPS. Here is the implementation TimeBasedUpdater.hpp
class TimeBasedUpdater
	static Uint32 start;
	static Uint32 current;

	// returns the value adjusted for time based movement
	static float GetCorrectedValue(float value);

	// needs to be restarted each frame
	static void Restart()
		start = SDL_GetTicks();


#include "TimeBasedUpdater.hpp"
#include <iostream>

Uint32 TimeBasedUpdater::start		= 0;
Uint32 TimeBasedUpdater::current	= 0;

float TimeBasedUpdater::GetCorrectedValue(float value)
	do {
		current = SDL_GetTicks();
	} while (start>=current);
	//Uint32 frame_time = current-start;
	std::cout << (value*(current-start)) << std::endl;
	return float(value*(current-start));	

(Yes, Restart() is being called at the end of each frame) All of the source is located at http://code.google.com/p/basicrpg34253/source/browse/#svn Let me know if you want something specific. Thanks; any thoughts?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!