• Advertisement
Sign in to follow this  

Time Based Movement

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