badatmath Posted June 2, 2022 Share Posted June 2, 2022 Here is most of the code to get the point across... // init time const direction = new Vector2(); const speed = 5; // render time direction.x = mouseX - window.innerWidth / 2; direction.y = mouseY - window.innerHeight / 2; direction.normalize(); const deltaY = direction.y; const deltaX = direction.x; const angle = Math.atan2(deltaY, deltaX); player.rotation = angle + 90 * Math.PI / 180; if (forward) { player.position.x += direction.x * speed; player.position.y += direction.y * speed; } if (backward) { player.position.x -= direction.x * speed; player.position.y -= direction.y * speed; } if (left) { // how? } if (right) { // how? } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.