首页 > 代码库 > dead reckoning variation

dead reckoning variation

Targeting

A target is a structure of information that describes the state, and change of state, of an object that exists in a remote person‘s instance of a game.

When you fire your laser, you send a packet of data to the server saying that

  1. You shot the laser,
  2. It was shot at some position in space (ox,oy) and
  3. that it‘s moving straight up.

 

for each frame {

  target.x_velocity = target.x_velocity + target.x_acceleration;

  target.y_velocity = target.y_velocity + target.y_acceleration;

  target.z_velocity = target.z_velocity + target.z_acceleration;

 

  target.x_position = target.x_position + target.x_velocity;

  target.y_position = target.y_position + target.y_velocity;

  target.z_position = target.z_position + target.z_velocity;

    smooth();

 

}

smooth(){

  laser.x = (laser.x + target.x_position) / 2;

  laser.y = (laser.y + target.y_position) / 2;

  laser.z = (laser.z + target.z_position) / 2;

}

 

smooth2(){

  laser.x = (laser.x * 99 + target.x_position) / 100;

  laser.y = (laser.y * 99 + target.y_position) / 100;

  laser.z = (laser.z * 99 + target.z_position) / 100;

}

dead reckoning variation