Pages: [1]
  Print  
Author Topic: Implementing WASD Movement  (Read 1151 times)
Offline (Unknown gender) marcelo
Posted on: August 27, 2018, 12:03:42 AM
Member
Joined: Aug 2018
Posts: 3

View Profile
Hi there,

I'm working on simple object that responds to WASD input by moving. The only issue I have is that after a couple seconds of holding down a key, the movement and keystrokes start to lag - I've included a GIF to show what I mean. I've tried both code and blocks, and both of them yield the same output.

Any suggestions would be greatly appreciated, thanks

Creation code:
Code: [Select]
left_speed = 0
right_speed = 0
up_speed = 0
down_speed = 0

Step code:
Code: [Select]
if keyboard_check(ord('W')) {
up_speed = 5
}
else {
up_speed = 0
}

if keyboard_check(ord('A')) {
left_speed = 5
}
else {
left_speed = 0
}

if keyboard_check(ord('S')) {
down_speed = 5
}
else {
down_speed = 0
}

if keyboard_check(ord('D')) {
right_speed = 5
}
else {
right_speed = 0
}

x -= left_speed
x += right_speed
y += down_speed
y -= up_speed
Logged
Offline (Male) HitCoder
Reply #1 Posted on: August 27, 2018, 07:38:05 AM

Member
Location: King's Lynn, England
Joined: Aug 2014
Posts: 149

View Profile WWW Email
From what I can tell this shouldn't be happening... :/
your code appears fine and i can't think what could be causing this, i'll have a look though

EDIT: Ok so it can't be a problem with your code... since I just tried it and everything works fine;
https://drive.google.com/file/d/1vLEruwIe3sshcvpoRoZoG6g2o1lDvtxs/view?usp=sharing
« Last Edit: August 27, 2018, 07:46:20 AM by HitCoder » Logged
DISCORD: HitCoder#4530
hi my name is John Cooper and i'm not good at anything
Offline (Male) hpg678
Reply #2 Posted on: August 27, 2018, 08:41:29 AM

Member
Location: Barbados
Joined: Mar 2017
Posts: 210

View Profile Email
i talked to one of the developers and he, as well as I, did get the same response at intervals. Rest assured he will look into as soon as possible. I've found that for me when I include a background, there is no lag, so u may want to do that as a temporary measure.
Logged
Hugar
Offline (Unknown gender) marcelo
Reply #3 Posted on: August 27, 2018, 10:03:58 PM
Member
Joined: Aug 2018
Posts: 3

View Profile
Thank you for trying out my code.

I added a background but I still experienced the same lag.. Since it worked for HitCoder I'm thinking maybe I can get it to work by running the code on a Windows installation of Enigma.
Logged
Offline (Male) hpg678
Reply #4 Posted on: August 28, 2018, 04:15:08 PM

Member
Location: Barbados
Joined: Mar 2017
Posts: 210

View Profile Email
I came across an article which in my opinion is one of the best articles I have ever read pertaining to game development. i believe it can help you with your problem, on so many other levels that may occur in your game, or rather future games.


https://www.yoyogames.com/blog/432/buttery-smooth-tech-tips-movement


I did a sample test and the results were much more than what I expected.



Logged
Hugar
Offline (Male) HitCoder
Reply #5 Posted on: August 29, 2018, 06:02:05 PM

Member
Location: King's Lynn, England
Joined: Aug 2014
Posts: 149

View Profile WWW Email
running the code on a Windows installation of Enigma.

What OS were you attempting to run this code on prior?

EDIT: After running the same code on Manjaro Linux, i'm noticing the problem, very prominently. I'll mess around with some things for a moment and get back to you.

EDIT2: In the game settings, I went to ENIGMA>API and set Platform from Linux X11 to SDL and it fixed things. I could hazard a guess that maybe in X11 mode when you hold a key down it registers the keystroke inputs in the same way a text editor would, in the way that holding w down will tell the game it's held down, then the window manager spams that key on and off like when you hold the letter down in a text form.
SDL seems to work fine on Linux, and tbh it's probably best to stick to cross-platform things anyway if they work. That's my personal belief though.
« Last Edit: August 29, 2018, 06:54:33 PM by HitCoder » Logged
DISCORD: HitCoder#4530
hi my name is John Cooper and i'm not good at anything
Offline (Unknown gender) marcelo
Reply #6 Posted on: August 29, 2018, 07:56:02 PM
Member
Joined: Aug 2018
Posts: 3

View Profile
 :o :o :o

After installing SDL and using it as the platform, the game runs flawlessly on Debian Linux. That makes a lot of sense now, that X11 was treating the keystrokes akin to a text editor. Thank you so much for your help, I appreciate it a lot.

Also thank you hpg678 for the article, it's really interesting. I had never thought of the concept of time-based movement... definitely something I'll try to implement.
Logged
Offline (Unknown gender) jbskaggs
Reply #7 Posted on: August 30, 2018, 08:21:47 AM
Member
Joined: Aug 2018
Posts: 10

View Profile Email
And this is why we need these things asked in forum not just on discord, as other people like myself can find these and learn from them.
Logged
Offline (Male) Goombert
Reply #8 Posted on: September 17, 2018, 09:41:50 PM

Contributor
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3068

View Profile
Hey guys, sorry for my late response here. I finally got around to this issue not only because I keep getting more reports about it but I also continue to have the issue myself, so it was getting really annoying. Regardless, I've got good news and we do have a fix!

As you can see on the GitHub issue posted oh-so-kindly by HitCoder, I first documented my findings while looking for the issue.
https://github.com/enigma-dev/enigma-dev/issues/1375

I tracked the cause down to the pull request in which we generalized the main loop so we could add SDL support.
https://github.com/enigma-dev/enigma-dev/pull/1259

The solution was pretty simple, I just had to tweak the event handling slightly to make it correct again.
https://github.com/enigma-dev/enigma-dev/pull/1390

I am hoping to get that reviewed and we'll have it merged into the repo soon. Thanks for your patience!
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Pages: [1]
  Print