#### Archived

This topic is now archived and is closed to further replies.

# Fine Tuning Analog Controller Scheme

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

## Recommended Posts

(I meant to post this here originally) My action mapper sends me my analog or joystick feedback on a scale -1 to 1 on both the RightLeft axis and UpDown axis. I managed to create a reasonably smooth camera-relative directional control out of it but I have one small problem left -- character velocity. If I use the magnitude of the original vector the character runs faster for diagonal directions on the analog or joystick. That's because going straight left(or right) gives me a magnitude of 1.0f(at full speed) and same for straight Up or Down on the analog - BUT at diagonals I have say 1.0f right AND 1.0f up ,which gives me root2 for magnitude which is bigger than 1.0f -- but it should only be 1.0f at any maximum direction. How do I get a magnitude for finding velocity out of the analog or joystick control??? Any ideas???? [edited by - pixelstar on February 21, 2004 12:45:52 AM]

##### Share on other sites
Calculate the angle of the direction the controler is pointing using arctan(UpDown / LeftRight) and say this angle is theta. Since x=cos(theta) and y=sin(theta) will give you a unit vector (x,y) you now only want a percentage of each of those values and since UpDown and LeftRight and values from 0 to 1 you just need to multiply by these two values ie x=abs(LeftRight) * cos(theta) and y=abs(UpDown) * sin(theta). Arctan gives results from -Pi/2 to Pi/2 so you will have to write in checks to get correct results.

[edited by - O_o on February 22, 2004 1:13:38 AM]

##### Share on other sites
Ahh. I see now. Thanks!!!!!

##### Share on other sites
After thinking unit vector I think x=LeftRight*abs(LeftRight)/sqrt((LeftRight^2+UpDown^2)) and y=UpDown*abs(UpDown)/sqrt((LeftRight^2+UpDown^2)) gives the same result and would be faster and no if statements needed, no trig functions and only one root.

[edited by - O_o on February 22, 2004 2:13:23 AM]

##### Share on other sites
Awesome! It''s working perfectly now!! :D
The control feels like Jak and Daxter now (my favortie PS2 game). Now I just have to smoothen out the animation blending and I''m on my way.
One question(subjective). Moreless asking for advice. I''m wondering if the directX action-mapper takes care of jopystick/analog DEADZONE good enough or if I should use my own DEADZONE and let the user modify the DEADZONE and sensitivity? Maybe it''s a waste of time? What would you do?

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633734
• Total Posts
3013590
×