Joystick and Space

Blitz3D Forums/Blitz3D Beginners Area/Joystick and Space

HuNTeD(Posted 2006) [#1]
Hey, I'm really new to the 3D world and I need some help with programming movement in space with a joystick. I'm not great at math or physics so this is quite difficult for me to understand right now.

I have a joystick that has a throttle that I want to use along with the twist handle. The throttle is for acceleration and the twist handel for the ship's yaw. Moving the stick left and right is for roll and forwards and backwards would be pitch. How would I get started with this? Please don't give away too much code because I like to learn on my own, I just need a jump start.


Stevie G(Posted 2006) [#2]
To determine which joypad command refers to which axis on your joypad take a look at Pongo's joypad configuration utility in the archives.


Stevie


HuNTeD(Posted 2006) [#3]
Ok, I got that but how would I make the ship rotate and stop slowly, I really only can do sharp turns and rotates.


Matty(Posted 2006) [#4]
Have a variable which stores the amount to turn by each frame while the joystick is held in a certain direction. As long as the joystick is still held in that direction, increase the value of the variable (up to a maximum) if the joystick is held in a different direction then alter the variable. Something along the lines of this:


turnvar#=turnvar#+joyx()*somefloatingpointvalue ;(somefloatingpoint value would be set to a value which scales the joyx() value appropriately - try a few values)
if abs(turnvar#)>maxturnvar# then turnvar#=sgn(turnvar#)*maxturnvar#

;and to ensure it doesn't shoot off to positive/negative infinity and gradually settles back to zero:
turnvar#=turnvar#*0.9

turnentity yourship,0,turnvar,0




Note - I just edited to include the line turnvar=turnvar*0.9 for reason stated above


HuNTeD(Posted 2006) [#5]
Works like a charm!! Thanks!