Advertisement

[Seeking Help]Coding with a Joystick/Buttons

Started by September 06, 2017 10:07 PM
2 comments, last by SantaCode 7 years, 2 months ago

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? 

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

Programmer and 3D Artist

Advertisement
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

This topic is closed to new replies.

Advertisement