0
\$\begingroup\$

I'm following a book I bought on Google Play that is teaching me the ropes of MonoGame, and in Chapter 2 it introduces creating an input wrapper that takes care of all the input methods for a game pad or keyboard. What's supposed to happen is that the WASD keys is mapped to the same inputs that the right thumb-stick would be on the game pad, but what happens for me is that the WASD keys move up and down correctly, but on the game pad it is flipped for some reason. I've looked over every line that I think would cause the problem, even replacing my code with the source code in the book, and the project they provide as an example works perfectly, but my project using THEIR code does not. If anyone can look over my project and see what the problem could be, that would be awesome!

Project: Here

MonoGame Book (Would Recommend So Far): Here

\$\endgroup\$
0

2 Answers 2

0
\$\begingroup\$

On a thumbstick Y positive 1 means "up":

if (GamePad.GetState( PlayerIndex.One ).ThumbSticks.Left.Y == 1.0f)
{
// Player one has pressed the left thumbstick up.
}

See Documentation for thumbstick on MSDN (note Monogame is a implementation of XNA):

Each of the thumbstick axis members is a signed value describing the position of the thumbstick. A value of 0 is centered. Negative values signify down or to the left. Positive values signify up or to the right. The controller typically does not generate thumbstick values within a dead zone, or marginal input region around the center position.

In your code private Vector2 ThumbStickState(Vector2 thumbStickValue, Keys up, Keys down, Keys left, Keys right) you state (comments mine):

        Vector2 r = new Vector2(0f, 0f);
        if ((GamePad.GetState(PlayerIndex.One).IsConnected))
        {
            r = thumbStickValue; //uses the thumbstick value returned by Monogame.
        }
        if (Keyboard.GetState().IsKeyDown(up))
            r.Y -= kKeyDownValue; //note the -=

Thus from your code, the keypress indicates a negative Y for up, while the thumbstick returns a positve 1 for up. Your code is working as specified (perhaps not as you expected).

I can't comment on the code from the book as I don't have it.

\$\endgroup\$
1
  • \$\begingroup\$ Okay, thank you. I've ditched this method from the book and made my own that seems to work how I want it to. Its weird though, as the Source code from the book works how they state it does, but my code that is taken directly from the source code to another project does not. Strange o.O \$\endgroup\$
    – Gman0064
    Jun 17, 2016 at 23:30
0
\$\begingroup\$

Screen coordinates differ from thumbstick direction and other vector types in that Y increases down. In your case, negating the GamePad Y value makes it match the screen coordinate system. (In a 3D project the projection matrix would fix it.)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .