Jump to content
  • Advertisement
SantaCode

[Seeking Help]Coding with a Joystick/Buttons

Recommended Posts

So I am developing a game. 
mP4PVbK.png

That is what it looks like. I want to script the controls so that when the joystick is selected and one of the buttons is pressed, the game moves the character with that specific limb. Is there any guidance on how I'd get started on that? 

Share this post


Link to post
Share on other sites
Advertisement

Hello @SantaCode You would just map the joystick button to the function which handles the movement of the joint while the joystick is being rotated.

if (joystick) { if (buttonA) { // movement for limb } }

You would need to code the part of the arm to rotate at the point of the joint connection based on the joypad direction.

shoulderJoint.setRotateValue(var);

You need to feed the y and x for the joystick which will give you the radiant value, then you can convert it to degrees to feed into the function. I don't know what library you're using however, but SFML for example requires degrees.

http://en.cppreference.com/w/cpp/numeric/math/atan2

Share this post


Link to post
Share on other sites
1 hour ago, Rutin said:

Hello @SantaCode You would just map the joystick button to the function which handles the movement of the joint while the joystick is being rotated.

if (joystick) { if (buttonA) { // movement for limb } }

You would need to code the part of the arm to rotate at the point of the joint connection based on the joypad direction.

shoulderJoint.setRotateValue(var);

You need to feed the y and x for the joystick which will give you the radiant value, then you can convert it to degrees to feed into the function. I don't know what library you're using however, but SFML for example requires degrees.

http://en.cppreference.com/w/cpp/numeric/math/atan2

4

Thank you so much. I'll keep this thread updated if I figure it out! :D

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!