Hey. i want to simulate client's work. And I need to find out how to work with playerhit, enemyhit, otherhit packets.
Now iam trying to predict player's projectile collision.
Hooked for playershoot and enemyhit packets. Mapping playershoot's time, location, angle, spd. When enemyhit happens, i compare enemy's position and predicted projectile position.
Code:
public Location PredictLocation(Location StartLoc, int spd, int starttime, float angle, int newtime)
{
float speed = (spd / 10f) * ((newtime - starttime) / 1000f);
Location ResultLoc = new Location();
ResultLoc.X = StartLoc.X + (float)Math.Cos(angle) * speed;
ResultLoc.Y = StartLoc.Y + (float)Math.Sin(angle) * speed;
return ResultLoc;
}
StartLoc - position in playershoot packet.
spd - projectile spd. I tested it on knight with sword, which spd is 100.
starttime - time in playershoot packet.
angle - angle from playershoot packet converted to normal angle (0-360).
newtime - time in enemyhit packet.
And this code can predict in close range. But the longer the distance, the greater the error. As I know, projectile hit, when its come closer than 0.5 unit. When I test it in 1 tile range, projectile predicted position was closer than 0.5, but when I shoot from ~3 tiles range, predicted position was further than 3.0.
Can someone tell me, where I made mistake?