-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Here is my walking function the input is a struct with an interface but you can feed it however you like, if it has a lat and long then you can move towards it. The speed is set to just barely under(max incubation speed) 20Km/h.
static void WalkTowards<T>(T input) where T : PointInfo {
var lat_speed = 0.0000490; var long_speed = 0.0000490; //update speed approximately 20Km/h
var sLat = input.Latitude; var sLon = input.Longitude; //destination Geos
var pLat = Program.session.Player.Latitude;
var pLon = Program.session.Player.Longitude;
var deltaX = pLat - sLat; //is my destination north or south?
var deltaY = pLon - sLon; //is my destination east or west?
// this works if you are in the north-west hemisphere
if (deltaX > 0) pLat -= lat_speed; else pLat += lat_speed; // head south else head north
if (deltaY > 0) pLon -= long_speed; else pLon += long_speed; // head west else head east
Program.session.Player.SetCoordinates(pLat, pLon); //our new point about 5-6m away
}
This is the loop that calls the walk function once per second.
var oldTime = TimeUtil.GetCurrentTimestampInMilliseconds(); //get the time now
var mDeltaTime = 0.0; //the amount of time since the last frame
do //loop this until we are at the destination
{
//update how far from the destination we are
playerDistance = Program.session.Player.DistanceTo(shop.Latitude, shop.Longitude);
//get the time now
var newtime = TimeUtil.GetCurrentTimestampInMilliseconds();
//find out how long its been since the last frame and add it to accumulator
mDeltaTime += newtime - oldTime;
//if it has been one second since we last updated the position update again and reset deltatime
if (mDeltaTime > 1000) { WalkTowards(shop); mDeltaTime = 0; LegTime++; }
//the is gives a reference point for the new delta calculation
oldTime = newtime;
}
while (playerDistance > 15); // I like to get up nice and close
Metadata
Metadata
Assignees
Labels
No labels