• Post Reply Bookmark Topic Watch Topic
  • New Topic

Velocity not returning to normal after bound key is released.  RSS feed

 
Andrew Holifield
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm attempting to create a "sprinting" functionality. The current keyPressed method uses the Shift key to set the walk speed (at 4), to the run speed (which is 8). It changes the velocity perfectly but stays at the runspeed even when Shift is released. I'm unsure how to have it return the walk speed back to normal when shift is released. If more of the code is needed to help my situation I will add it. Thank you very much for your time. ^_^

 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is with this line:It literally says: Take a value from p.walkSpeed and assign it to p.walkSpeed, which can be translated to: Do nothing.
 
Fred Kleinschmidt
Bartender
Posts: 572
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Why the if-test? You just set sprinting=true, so the if-test is always going to succeed.
You need to save the original walkSpeed so that the keyReleased method can restore it. Also, your version of keyReleased() fails to set sprinting back to false.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!