I have a problem moving 3D model, when I press two keys at the same time. Let's say I want to move my model from center of the screen (camera isn't moving) diagonaly to upper left corner.
Even tho I press two keys, the model will move in the direction of the key pressed first or if I press A key after already holding down W key, the model will continue to travel upwards.
Any ideas on how should I fix this?
protected void UpdateInput(GameTime gameTime) { KeyboardState currentKeyState = Keyboard.GetState(); float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds; float moveX = 0.0f; float moveZ = 0.0f; if (currentKeyState.IsKeyDown(Keys.W)) moveX += 0.1f* time; else if (currentKeyState.IsKeyDown(Keys.S)) moveX -= 0.1f * time; else if (currentKeyState.IsKeyDown(Keys.A)) moveZ -= 0.1f * time; else if (currentKeyState.IsKeyDown(Keys.D)) moveZ += 0.1f * time; modelPosition += new Vector3(moveX, 0, moveZ); }
protected override void Update(GameTime gameTime) { KeyboardState keyboardState = Keyboard.GetState(PlayerIndex.One); if (keyboardState.IsKeyDown(Keys.Escape)) this.Exit(); UpdateInput(gameTime); modelPosition += modelVelocity; modelVelocity *= 0.95f; base.Update(gameTime); }
Thanx.