Skip to content

Instantly share code, notes, and snippets.

@buesing
Created June 28, 2019 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buesing/69048a272df1891452ef4cb7405f8c6a to your computer and use it in GitHub Desktop.
Save buesing/69048a272df1891452ef4cb7405f8c6a to your computer and use it in GitHub Desktop.
slowdownBall() {
// if the ball is on the way to the opponent,
// we slow it down so it will be on the opponents side
// approximately at the time they actually hit it
// NOTE that we still only receive the hit half a roundtriptime later
if (this.physics.ball.velocity.z > 0) {
return;
}
const velocity = this.physics.ball.velocity.length();
const dist = new Vector3().subVectors(this.ball.position, this.paddleOpponent.position).length();
const eta = dist / velocity;
const desirableEta = eta + (this.communication.latency / 1000);
this.physicsTimeStep = 1000 * (desirableEta / eta) * 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment