# SDL and use of a Gamepad how to get smooth movements?

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

## Recommended Posts

I have a logitech rumblepad gamepad. How can I make a smooth movement when the user uses the joystick on it? e.g. Player moves fwd, and the rotates the joystick to the right or left the car should turn smoothly to the left or right. But how do I do this? I am assuming I need to use SDL_JOYAXISMOTION
case SDL_JOYAXISMOTION:
if(sdlEvent->jaxis.which == 0)
{
//If joystick 0 has moved
//If the X axis changed
if(sdlEvent->jaxis.axis == 0)
{
//If the X axis is neutral
if((sdlEvent->jaxis.value > -8000) && (sdlEvent->jaxis.value < 8000))
{
gameStateModes.userMovements[LOOKLEFT] = false;
gameStateModes.userMovements[LOOKRIGHT] = false;
}
else
{
if(sdlEvent->jaxis.value < 0)
gameStateModes.userMovements[LOOKLEFT] = true;
else
gameStateModes.userMovements[LOOKRIGHT] = true;
}
}
//If the Y axis changed
if(sdlEvent->jaxis.axis == 1)
{
//If the Y axis is neutral
if((sdlEvent->jaxis.value > -8000) && (sdlEvent->jaxis.value < 8000))
{
gameStateModes.userMovements[LOOKUP] = false;
gameStateModes.userMovements[LOOKDOWN] = false;
}
else
{
if(sdlEvent->jaxis.value < 0)
gameStateModes.userMovements[LOOKDOWN] = true;
else
gameStateModes.userMovements[LOOKUP] = true;
}
}


I am not sure but I am thinking the 8000 value is suspect... From what I can tell when I move the joystick around to move left or right the wheels stay still unless I am moving forward or back then they will move left and right, but its hard to get the left right movements working... [Edited by - MARS_999 on May 14, 2008 3:57:42 PM]

##### Share on other sites
Quote:
 Original post by MARS_999I have a logitech rumblepad gamepad. How can I make a smooth movement when the user uses the joystick on it? e.g.Player moves fwd, and the rotates the joystick to the right or left the car should turn smoothly to the left or right. But how do I do this?I am assuming I need to use SDL_JOYAXISMOTION *** Source Snippet Removed ***I am not sure but I am thinking the 8000 value is suspect... From what I can tell when I move the joystick around to move left or right the wheels stay still unless I am moving forward or back then they will move left and right, but its hard to get the left right movements working...

//If the X axis is neutral						if((sdlEvent->jaxis.value > -8000) && (sdlEvent->jaxis.value < 8000))						{							gameStateModes.userMovements[LOOKLEFT] = false;							gameStateModes.userMovements[LOOKRIGHT] = false;						}

I think it's because you're constantly setting the axis back to neutrality. Trying taking this out, and see if it works?

Also are you getting this sorta jerky movement with the car, or with the rotation turning of the car as if it's only going pixel by pixel?

if so, I believe it's because you're calling the joystick to go back to neutrality each time you're calling for this function. Try taking this out, and see if it help.

If not let me know.

I've worked on this type of project before when I bought my xbox360 controller for windows, so if this doesn't work let me know, and I'll pull out my old code.

Gotta love debugging...lol

##### Share on other sites
I think I got it working now. I just dumped the fwd,back movements off the joystick and just using it for left/right now and added fwd, back buttons instead on the gamepad.

##### Share on other sites
Glad to see you got it working! ;)

I actually looked at my old forum post back when I had this problem, and well what I mentioned didn't help at all... sorry, should of remembered that as well, but glad to see you got it working.

what game is it? When it's done I'd like to demo it

##### Share on other sites
I think I am going make it a crash up derby game but not sure just yet. Right now I am just collecting coins and powerups with the hummer!!! :) So fun.

##### Share on other sites
One last thing, I am not sure why, but when you let up on the button or press it down it will poll for a few more cycles. I put a std::cout message in the event and got like 5 or 6 more messages after the event was done... I am having some weird behavior when my car drives vs. if I use the keyboard the cars works fine. Any ideas? Thanks