I’m getting more and more into the aspect of learning python and logic bricks
and I’ve been following tutorials to learn, but every tutorial Iv’e been following
so far have used a simpler forwards/backwards movement scheme where the left
and right buttons are used to adjust angles.
The next thing I want to learn is to improve on my control schemes, the first thing
I did was replace the movement with joystick controls and made a simple 8
directional movement scheme which leaves much to be desired, as it doesn’t have
proper control over angle.
Since the joystick has many angles available I had an idea but to execute it I’d
need to know if Blender’s coding stores the values for a joystick’s angle and how
to apply it to the object.
After much searching I ended up here, since I couldn’t find documentation on
using the 360 degrees of the joystick on my objects.~
A method is to use python programming, for example a code like this:
from bge import logic
from math import radians, degrees
from mathutils import *
obj = logic.getCurrentScene().objects['shuttle']
Stick = obj.sensors['joystick'] #Joystick sensor, Event Type = Axis
Roll, Pitch, Yaw = obj.worldOrientation.to_euler()
[fiStick, tetStick, thrStick] = Stick.axisValues
scale = radians(90./32768) # scale factor (32768) depends on joystick!!!
RollDem = 2*scale*fiStick # +/- 180deg
PitchDem = scale*tetStick # +/- 90deg
YawDem = -scale*thrStick # +/- 90deg
# Il joystick imposta gli angoli di eulero, non le velocità angolari, perciò i movimenti combinati non avvengono come ci si aspetterebbe: il rollio è sempre attorno all'asse x locale, il beccheggio intorno alla normale all'asse x sul piano orizzontale (intersezione del piano y-z locale con il piano orizzontale) e l'imbardata intorno all'asse z globale.
Roll = Roll + 0.1*(RollDem-Roll)
Pitch = Pitch + 0.1*(PitchDem-Pitch)
Yaw = Yaw + 0.1*(YawDem-Yaw)
obj.worldOrientation = (Roll, Pitch, Yaw)
Here, it is assumed that your object is called “shuttle”, and you have added a Joystick sensor called ‘joystick’, connected to the python controller linked to the above code.