Sign in to follow this  

DInput: Up is fine, left is fine, but Up+Left is one or the other?

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Howdy I'm sure this is a common thing, but I've done some searches and can't find an answer. I'm using DirectInput for keyboard input for a game but I have a problem. If I press up, the character jumps. Fine, no probs. If I press left, the character moves left. Couldn't be better. However, if I press up and left, hoping for a jump to the left, it doesn't always happen. Sometime it does if you time it right, but most of the time you get either up or left. So my question is, how do you handle input that allow for combinations to work aswell as individual keys. I tried putting a delay in between keyboard reading, but then the character is slow to respond which is annoying. Any help would be greatly appreciated. I may even name my first born after you. Rob.

Share this post


Link to post
Share on other sites
How are you doing input, buffered or unbuffered? If you are doing buffered, you may need to set the Buffer size higher so it can hold more than one entry...

Share this post


Link to post
Share on other sites
They are two possibilities ...

- First is to use

// If both Up and Left Keys are down, then
if ((KeyBoard.KeyDown (DIK_UP)) && ((KeyBoard.KeyDown (DIK_LEFT))
{
// do your stuff
}

- Other is calculating when making transformation. When Up Key is pressed the player jumps at certain height (store height value). When left key is pressed the player moves in the left direction (store left direction value). Just calculate (both left and height) things before you set up transformation.

Ofcourse this all depends upon your game requirements. If you want your player to control his movement during jump then I would rather prefer going for the second one.

I hope I was clear.

Share this post


Link to post
Share on other sites
I've done a lot of stuff with directinput and chances are you're using else if for your key reading code.

// If both Up and Left Keys are down, then
if (KeyBoard.KeyDown (DIK_UP))
{
// do your stuff
}
else if(KeyBoard.KeyDown (DIK_LEFT))
{
//
}

That would mean if you pressed up and left it'd move up. Get rid of the else and it should move diagonally. That's the most simple/likely answer.

Share this post


Link to post
Share on other sites

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this