From f2d517df9df8528029fe54f1d940c750bccb0233 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 12:33:51 +1100 Subject: [PATCH] BUGFIX: Infinitely small motion on an axis after repeated key release; read more I've patched this issue by setting motion's elements to CHARACTER_WALKING_SPEED or negative CHARACTER_WALKING_SPEED if they're above or below zero, respectively. --- client/scenes/in_world.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index abd68d4..1819fb2 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -266,6 +266,7 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) { if (motion.x != 0 && motion.y != 0) { motion *= CHARACTER_WALKING_MOD; } + //set the info localCharacter->SetMotion(motion); localCharacter->CorrectSprite(); SendLocalCharacterMotion(); @@ -291,7 +292,24 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) { motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED); break; } + //BUGFIX: reset cardinal direction speed on key release + if (motion.x > 0) { + motion.x = CHARACTER_WALKING_SPEED; + } + else if (motion.x < 0) { + motion.x = -CHARACTER_WALKING_SPEED; + } + if (motion.y > 0) { + motion.y = CHARACTER_WALKING_SPEED; + } + else if (motion.y < 0) { + motion.y = -CHARACTER_WALKING_SPEED; + } //handle diagonals + if (motion.x != 0 && motion.y != 0) { + motion *= CHARACTER_WALKING_MOD; + } + //set the info localCharacter->SetMotion(motion); localCharacter->CorrectSprite(); SendLocalCharacterMotion();