From ad6b1bf9c5887b1f9d5cf595c66766a3a5842993 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 20 Mar 2015 19:42:54 +0100 Subject: [PATCH] Set correct speed on diagonal movement --- src/player.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/player.cpp b/src/player.cpp index f8d71e1..401b243 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -20,6 +20,13 @@ void Player::Update(sf::RenderWindow* window, InputManager inputManager) { this->velocity.y = inputManager.IsPressed(InputManager::Down) * this->speed - inputManager.IsPressed(InputManager::Up) * this->speed; + // Set correct speed on diagonal movement + if((this->velocity.x == this->speed || this->velocity.x == -this->speed) + && (this->velocity.y == this->speed || this->velocity.y == -this->speed)) { + this->velocity.x *= sqrt(this->speed * 2 + this->speed * 2) / (this->speed * 2); + this->velocity.y *= sqrt(this->speed * 2 + this->speed * 2) / (this->speed * 2); + } + // Update camera position //|------------|--------------|------------| //| 1 | 2 | 1 |