How do I use "Zrot list" with Axisvalues?

A while back, I asked about “twist” and “paddle”. Chtames told me the following:

“In BGE python, the joystick sensor function axisValues returns a list [ x, y, z, zRot]”

How exactly do I use any of these list items? I haven’t seen any code for it, aside from 0,1,2, and 3. 4 is apparently “out of range.”

with lists zero is the first element

so list [3] is zrot

you got a bit lucky here, i didnt thought i still had it but here is my movement script with joystick and/or keyboard controls.
only tested with xbox controller, i made this a few years back but should still work today (this is an old backup file due to hdd crash).

Maybe it helps you.

#edit
Not sure, search resource section, looks like i have a blend there

##################################################                                               #
#           MOVEMENT SCRIPT BY COTAX            #
#                 Blender 2.6+                  #
#                                               #
#################################################
from bge import logic, events    


def get_keys():
    
    cont    = logic.getCurrentController()
    gamepad = logic.joysticks[0]
     
    # Set the keys    
    if gamepad == None:
        
        #keyboard
        keyboard    = logic.keyboard
        
        # Make an (if key pressed) active check
        active          = logic.KX_INPUT_ACTIVE
        just_activated  = logic.KX_INPUT_JUST_ACTIVATED       
        
        forwards    = keyboard.events[events.WKEY] == active
        backwards   = keyboard.events[events.SKEY] == active
        left        = keyboard.events[events.AKEY] == active
        right       = keyboard.events[events.DKEY] == active
        sprint      = keyboard.events[events.LEFTSHIFTKEY] == active
        jump        = keyboard.events[events.SPACEKEY] == just_activated        
    else:       
        #controller
        joystick    = cont.sensors["Joystick"]
        
        dead_zone   = 0.3
        
        left        = gamepad.axisValues[0] < -dead_zone
        right       = gamepad.axisValues[0] > dead_zone
        forwards    = gamepad.axisValues[1] < -dead_zone
        backwards   = gamepad.axisValues[1] > dead_zone
        sprint      = joystick.getButtonStatus(8)
        jump        = joystick.getButtonStatus(0)


    return forwards, backwards, left, right, sprint, jump




def get_speeds():
    
    cont    = logic.getCurrentController()
    own     = cont.owner
    
    if 'walk_speed' in own:
        #use object properties as speeds
        walk_speed      = own['walk_speed']
        run_speed       = own['run_speed']
        walk_back_speed = own['walk_back_speed']
        run_back_speed  = own['run_back_speed']
        strafe_speed    = own['strafe_speed']
        jump_speed      = own['jump_speed']
        
    else:
        #use default speeds
        walk_speed      = 2.5
        run_speed       = 4.5
        walk_back_speed = 1.5
        run_back_speed  = 2.5
        strafe_speed    = 1.5
        jump_speed      = 4.5
    
    return walk_speed, run_speed, walk_back_speed, run_back_speed, strafe_speed, jump_speed
 
 
def main():


    cont    = logic.getCurrentController()
    own     = cont.owner


    # Run the script or not
    if own['run_script'] == True: 
        
        # get the sensors.
        groundcheck = cont.sensors['GroundCheck']


        # get the keys 
        forwards, backwards, left, right, sprint, jump = get_keys()[0], get_keys()[1], get_keys()[2], get_keys()[3], get_keys()[4], get_keys()[5]
       
        # get the speeds
        walk_speed, run_speed, walk_back_speed, run_back_speed, strafe_speed, jump_speed = get_speeds()[0], get_speeds()[1], get_speeds()[2], get_speeds()[3], get_speeds()[4], get_speeds()[5] 
   
        if groundcheck.positive:
            
            # turn sliding off
            x = 0.0
            y = 0.0
            z = own.localLinearVelocity.z
           
            # set speeds
            if forwards:
                
                if sprint:
                    y = run_speed
                else:
                    y = walk_speed 
                  
            if backwards:
                
                if sprint:
                    y = -run_back_speed
                else:
                    y = -walk_back_speed 
               
            if left:
                
                x = -strafe_speed
                    
            if right:
                
                x = strafe_speed
            
            if jump:
                
                z = jump_speed
                
        else: 
            # turn sliding on when in air                       
            x = own.localLinearVelocity.x
            y = own.localLinearVelocity.y
            z = own.localLinearVelocity.z


        # set the speed               
        own.localLinearVelocity = [x, y, z]

But, if I were to write the following code:

axisdat = joy.axisValues

own.applyMovement([axisdat[2] * 0.00001, axisdat[3] * 0.00001, 0], True)

and set the “axis number” on the joystick actuator, I get movement from the second analog stick. I know this page is ancient, but I’ve heard from another discussion about using Zrot from a “list.” So, how do I use a list to get Zrot?

http://www.tutorialsforblender3d.com/GameModule/ClassSCA_JoystickSensor_5.html

Please have a look at the BGE API.

It is not x,y,z,zrot

it is axis 1, axis 2, axis 3, axis 4 …

Which one is first, second and so on depends on your joystick (and your joystick driver). You can’t guaranty the first two axis to be left/right and forward/backward axis. It is a good assumption as most manufacturer map the axis number that way. Additional you need to know the direction of the axis e.g. if positive values mean left or mean right direction.

You need to find the mapping of your joystick

[table=“width: 500, class: outer_border”]

[th]axis[/th]
[th]meaning (Joystick type A)[/th]
[th]meaning (Joystick type B)[/th]
[th]meaning (Joystick type C)[/th]


1
left .. right
right .. left
left .. right


2
forward .. backward
forward .. backward
forward .. backward


3
left twist .. right twist
paddle forward .. backward
 n/a 


4
paddle forward .. backward
left twist .. right twist
 n/a 

[/table]

Be aware the list (axisValues) starts with 0. So the index of axis 1 is 0, the index of axis 2 is 1 … . You need to substract 1 to convert the axis number to index:


leftRightAxis = 1
leftRightValue = axisValues[leftRightAxis -1]

im not sure but i do know that i had problems with it aswell, thats why i didnt use the axis from the joystick sensor but directly from the controller input.

gamepad = logic.joysticks[0]

and the buttons i grab them from tje joystick sensor

joystick    = cont.sensors["Joystick"]

Hold on…so are “twist” and “paddle” just the 2nd analog stick’s left, right, forward, and backward? And are joystick “types” simply the way the controllers are made, and not code? I was hoping there was code for reading the stick’s position along the z-axis, so that I could convert it to object orientation.