Since I'm not entirely sure if it works correctly, but has worked when briefly testing. I'm gonna release some part of source which is like 5 years old and was never used in my projects.
I found the formula for this on one of the silkroad related boards. I actually would like to credit someone but I'm not sure who wrote it. Might be illstar as I read through a lot of stuff he wrote.
Might be helpful to you
Code:
public void Update()
{
float ToGoX;
float ToGoY;
double distance;
double speed = 0.0;
try
{
if (m_Standing)
{
m_LastCalculated = m_Start;
}
else
{
Double timeLeft = DateTime.Now.Subtract(m_lastUpdate).TotalMilliseconds;
ToGoX = (m_LastCalculated.X - m_Destination.X);
ToGoY = (m_LastCalculated.Y - m_Destination.Y);
distance = Math.Sqrt(ToGoX * ToGoX + ToGoY * ToGoY);
switch (m_SpeedMode)
{
case eSpeedMode.Walking:
speed = ((m_WalkSpeed / 10.0) * timeLeft) / 1000.0;
break;
case eSpeedMode.Running:
speed = ((m_RunSpeed / 10.0) * timeLeft) / 1000.0;
break;
}
if (distance == 0.0)
{
m_LastCalculated = m_Start;
}
float modi = (float)(((100.0 / distance) * speed) * 0.01);
ToGoX *= modi;
ToGoY *= modi;
float tmpX = m_LastCalculated.X;
float tmpY = m_LastCalculated.Y;
tmpX -= ToGoX;
tmpY -= ToGoY;
//Set X, Y
m_LastCalculated.X = tmpX;
m_LastCalculated.Y = tmpY;
m_lastUpdate = DateTime.Now;
}
}
catch (Exception ex)
{
Debug.Print("PositionTracker->Update()->Exception:" + ex.Message);
}
}