pike/val Public Public: anyone can read this; nobody can change it.
forked from benjivers/val
workbenchthis machine
Draw your own arrow at the facing you are holding, in either view
The top-down view aims with the pointer and drew the arrow at the angle the server last heard, which is the same lag as the first-person camera had. The facing this browser holds is the one to draw in both views; the server hears it through the same input timer as before. Co-Authored-By: Claude Opus 5 <[email protected]>
1 file
changed +7
−3
static/val.js +7 −3
| @@ -107,12 +107,14 @@ const send = (message) => { | ||
| 107 | 107 | |
| 108 | 108 | // ------------------------------------------------------------------- input |
| 109 | 109 | |
| 110 | /** | |
| 111 | * Swap the view. The two share one facing — whichever you leave, you keep | |
| 112 | * looking the way you were looking — so nothing here touches the angle. | |
| 113 | */ | |
| 110 | 114 | function setMode(next) { |
| 111 | 115 | mode = next; |
| 112 | 116 | $("stage").dataset.mode = next; |
| 113 | 117 | if (next !== "fp" && document.pointerLockElement === view) document.exitPointerLock(); |
| 114 | // The two views share one facing: whichever you leave, you keep looking | |
| 115 | // the way you were looking. The server has nothing to add to that. | |
| 116 | 118 | } |
| 117 | 119 | |
| 118 | 120 | addEventListener("keydown", (event) => { |
| @@ -335,7 +337,9 @@ function predict(dt, now) { | ||
| 335 | 337 | drawnMe.id = snap.me.id; |
| 336 | 338 | drawnMe.x = local.x; |
| 337 | 339 | drawnMe.y = local.y; |
| 338 | drawnMe.angle = mode === "fp" ? head.angle : snap.me.angle; | |
| 340 | // Either view: the facing is the one this browser is holding, whether the | |
| 341 | // mouse moved it or the pointer aim did. The server hears it a moment later. | |
| 342 | drawnMe.angle = head.angle; | |
| 339 | 343 | } |
| 340 | 344 | |
| 341 | 345 | function frame(now) { |