Fix velocity by making a vector

This commit is contained in:
2025-12-13 19:42:01 -08:00
parent 88241ad705
commit 1baf76d901

View File

@@ -78,7 +78,7 @@
const reverseMoveButton = document.querySelector("#move-backward"); const reverseMoveButton = document.querySelector("#move-backward");
const forwardMoveButton = document.querySelector("#move-forward"); const forwardMoveButton = document.querySelector("#move-forward");
const fps = document.querySelector("#fps"); const fps = document.querySelector("#fps");
const velocity = [0, 20]; // meters per second const velocity = [-100, -50]; // meters per second
let previous, zero, frameCount = 0; let previous, zero, frameCount = 0;
@@ -118,11 +118,20 @@
[[, x], [, y] = def] = [...hitbox.style.transform.matchAll(regex)]; [[, x], [, y] = def] = [...hitbox.style.transform.matchAll(regex)];
} }
const positionX = changeX + +x; let positionX = changeX + +x;
const positionY = changeY + +y; let positionY = changeY + +y;
if (positionY > 150) positionY = positionY - 150 - 150;
else if (positionY < -150) positionY = -1 * positionY - 150 + 150;
if (positionX > 200) positionX += -400;
else if (positionX < -200) positionX += 400;
hitbox.style.transform = `translate(${positionX}px, ${positionY}px)`; hitbox.style.transform = `translate(${positionX}px, ${positionY}px)`;
// console.log(hitbox.style.transform);
// hitbox.style.transform = `translate(0px, ${position}px)`; // hitbox.style.transform = `translate(0px, ${position}px)`;
if (+y < 100) requestAnimationFrame(t => animate(t)); // if (+y < 200)
if (timestamp < 10000) requestAnimationFrame(t => animate(t));
} }
function moveTank(el) { function moveTank(el) {

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB