Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Character Movement Getting Stuck #2

Open
1chooo opened this issue May 2, 2023 · 5 comments
Open

Character Movement Getting Stuck #2

1chooo opened this issue May 2, 2023 · 5 comments

Comments

@1chooo
Copy link

1chooo commented May 2, 2023

Descriptions

Thank you very much for open sourcing this project, and also for the tutorial on YouTube. However, I encountered an issue while playing and submitted an issue report. The problem is that if I move to the right and suddenly click up or down, the character will get stuck and cannot continue moving to the right. The same issue occurs when moving in any of the four directions.

How to reproduce

  1. click 'right'
  2. continue click 'up' and 'down'
  3. happen stuck in the original place.

The video situation

Screen.Recording.2023-05-03.at.1.51.17.AM.mov
@hunick1234
Copy link

it's a logic problem.
like this sample code:

if (

  this.keys.w.pressed ||
  this.keys.a.pressed ||
  this.keys.s.pressed ||
  this.keys.d.pressed

) {

  this.isAnimation = true;
  if (this.keys.w.pressed) {
   //do somthing like move

  } else if (this.keys.s.pressed) {
    //do somthing like move

  } else if (this.keys.d.pressed) {
     //do somthing like move

  } else if (this.keys.a.pressed) {
     //do somthing like move

  } 
}

it scans from w to a, so now u click right (d key) it work.
Watch the scans order if you click up (w key) or down (s key)
it does the first the charter move change but if you click left (a key) it doesn't work right?

Now you want lock only one key maybe you can lock in addEventListener

window.addEventListener("keydown", (KeyboardEvent) => {
//if keys is true return dont set anothe key
switch (KeyboardEvent.key) {

case "s":
  keys.s.pressed = true;
  console.log("s");
  break;
case "w":
  keys.w.pressed = true;
  console.log("w");
  break;

case "a":
  keys.a.pressed = true;
  console.log("a");
  break;

case "d":
  keys.d.pressed = true;
  console.log("d");
  break;

default:
  break;

}
});

@1chooo
Copy link
Author

1chooo commented May 11, 2023

Hey @hunick1234

I may not have described my issue clearly earlier. My problem is that when I keep pressing the right arrow key (d) and then press the up arrow key (w) or the down arrow key (s), my character stops moving altogether, whereas in normal gameplay, with the previous arrow key still held down (in this case, the right arrow key), it should continue moving in that direction even if I continuously click the up or down arrow keys.

So, it's not that it doesn't work after clicking the left arrow key (a), because in the aforementioned situation, clicking the left arrow key (a) does work.

Thank you very much for discussing this with me, and I welcome further exploration.

BR,
@1chooo

JuanGlv added a commit to JuanGlv/Pokemon that referenced this issue May 12, 2023
Se finalizó la base del archivo CSS, acercándonos un poco más a la conclusión de la misma.
@hunick1234
Copy link

hunick1234 commented May 12, 2023 via email

@1chooo
Copy link
Author

1chooo commented May 12, 2023

@hunick1234

嗨!你好!看起來我們確實有相同的語言共通性。

沒問題,非常感謝你熱心的回應,以下是我上述回應的中文原文:

我可能之前沒有描述好,我的問題是當我今天一直按右鍵(d)不放開的情況下,按了上鍵(w),以及按了下鍵(s)人物就停留在原地不動了,然而正常遊戲操作會在前一個按鍵不放開的前提下,這邊是拿右鍵(d)做舉例,就算連續點擊上鍵(w)下鍵(s),也應該要繼續往右。

所以並非是再點擊左鍵(a)後不會運作,因為在上述情況下,點擊左鍵(a)是會運作的。

非常感謝你熱心地和我討論,也非常歡迎做後續的探討。

BR,
@1chooo

@hunick1234
Copy link

hunick1234 commented May 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants