OBS! Shooting might cause unexpected behaviour in this version, so beware (ie. the game bugs out completely)
OBS! Tabbing out from the game also creates some funky bugs.
http://rymdenrunt.appspot.com/swf/rymden2.html
course == current ship state
target == ship state retrieved from server
New interpolation code: (this is not done on your own ship)
- Code: Select all
public function interpolate():void {
//update target to current time
while (target.tick < course.tick) {
updateHeading(target);
}
//Calculate position diff
var diff:Point = new Point(target.x - course.x, target.y - course.y);
var distance:Number = Math.sqrt(Math.pow(diff.x, 2) + Math.pow(diff.y, 2));
//warp ship if diff is to large
if (distance > BLIP_OFFSET) {
blip();
return;
}
//smooth step course speed to target speed
var velStep:Number = 0.5;
course.speed.x = target.speed.x + velStep * diff.x;
course.speed.y = target.speed.y + velStep * diff.y;
//smooth step course angle to target angle
var angleDiff:Number = NumberUtil.angleDifference(target.angle, course.angle);
course.angle += angleDiff*0.8;
course.angle = NumberUtil.clampRadians(course.angle);
}