SFML community forums
Help => Graphics => Topic started by: SuperV1234 on April 05, 2010, 11:40:01 am
-
I created a simple 8-dir movement for my game, however when moving in a diagonal direction the player goes faster than intended.
This is the code. How can I prevent it?
switch (input)
{
case KeyCode.Left:
nextX = -1;
break;
case KeyCode.Right:
nextX = 1;
break;
case KeyCode.Up:
nextY = -1;
break;
case KeyCode.Down:
nextY = 1;
break;
}
X = X + nextX * speed;
Y = Y + nextY * speed;
nextX = 0;
nextY = 0;
-
Decrease the step size when two keys are pressed simultaneously.
if (nextX != 0.f && nextY != 0.f)
{
nextX *= 0.707106781f; // == sqrt(2) / 2
nextY *= 0.707106781f;
}
-
Thanks! :D