Created
June 28, 2019 12:36
-
-
Save buesing/69048a272df1891452ef4cb7405f8c6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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